parent.html : OnClick="popup();"
1. 页面打开并显示内容
2. 但是 js 功能不工作。 js函数定义在js文件中。
3.我用firebug检查,js文件加载成功。
4. 仅在刷新页面后有效。有什么想法吗?我犯了什么错误?
js 函数:
<script>
function popup(){
var test = "<html><head>";
test += "<script src= " + '"'+"jqueryTestfile.js"+'"'+ "> <" + '/' + "script>";
test += "</head><body>";
test += "<div id=" + '"' +"anyId" + '"' + ">";
test += "</div>";
test += "</body></html>";
win.document.write(test);
}
</script>
子弹出窗口和源代码如下所示:
<html> <head>
<script src = "jQueryTestFile.js"> </script>
</head> <body> <div id = "anyId">
some content here ...
</div> </body> </html>
最佳答案
我在拒绝后解决了我的问题。尝试并希望分享:
<script type="text/javascript">
window.document.close();
</script>
为什么即使在下载文件后 js 功能仍无法正常工作: 因为我正在使用 window.document.write 打开(弹出)一个新窗口()
并且此方法导致了问题,因此我使用 window.document.close()
强制页面“完成加载”。
关于javascript - js文件用html页面下载,但js函数只有在刷新页面后才有效,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6591272/