【发布时间】:2016-02-23 22:34:20
【问题描述】:
执行document.write() 后,Google Chrome 显示 HTML 代码从 Code A 更改为 Code B。似乎document.write() 覆盖了整个页面。如果是,如何将脚本标签附加到head标签内?
代码 A:执行前document.write()
<!--DOCTYE html-->
<html>
<head>
<script src=".\js\main_CasCode.js"></script>
</head>
<body onload="main()">
<p>hi</p>
</body>
</html>
代码 B:执行后 document.write()
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
</head>
</html>
文件中的 JavaScript .\js\main_CasCode.js
function main() {
//console.log = function() {};
loadjQuery();
//waitjQueryLoaded_and_start();
}
function loadjQuery() {
console.log("Loading jQuery...");
var s = '<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>';
document.write(s); //<----Problem Here
}
【问题讨论】:
标签: javascript jquery html overwrite document.write