我有一個母版頁,其中jvscrpt函數稱爲openWin(),它打開一個新窗口。 這裏是我的代碼:「我點擊」JavaScript呈現HTML頁面仍在加載
<html>
<head>
<script type="text/javascript">
function openWin()
{
win=window.open();
win.document.write("<html>");
win.document.write("<head>");
win.document.write("<style type=\"text/css\">");
win.document.write("@media print{.input {display:none}}");
win.document.write("</style>");
win.document.write("</head>");
win.document.write("<body>");
win.document.write("<table align=\"center\">");
win.document.write("<tr><td>result:</td><td>100,--€</td></tr>");
win.document.write("<tr><td colspan=\"2\" id=\"idcko\"><input type=\"button\" value=\"click\" class=\"input\" onclick=\"window.print();\"/></td></tr>");
win.document.write("</table>");
win.document.write("</body>");
win.document.write("</html>");
}
</script>
</head>
<body>
<form>
<input type="button" value="Click me!" onclick="openWin();" />
</form>
</body>
</html>
當我點擊按鈕會出現一個新窗口,但瀏覽器無法停止加載頁面。該頁面具有全部功能,但是例如,當我想在Mozilla中查看源代碼時,我只能看到一個空白頁面。 請幫助...
它與打開一個新窗口無關,它只是在文件已經完成寫入時使用document.write了。如果你在當前頁面上執行document.write('test')(加載後),你會得到同樣的效果。他們是saem的原因是因爲window.open()將打開一個完整但空的文檔的新頁面。我建議嘗試使用DOM功能來添加您的HTML元素,應該更好一點。 – Chris 2011-01-31 12:38:19