请教个问题,这是我的代码:
var head = document.getElementsByTagName("head")[0] || document.documentElement;
var script = document.createElement("script");
script.setAttribute("type", "text/javascript");
script.setAttribute("charset", "utf-8");
script.setAttribute("src", G(Q, b) + "&d=" + (new Date()).getTime());
script.onload = script.onreadystatechange = function() {
if (!this.readyState || this.readyState == "loaded" || this.readyState == "complete") {
script.onload = script.onreadystatechange = null;
if (head && script.parentNode) {
head.removeChild(script);
}
}
};
head.insertBefore(script, head.firstChild);
为什么我只要在head.insertBefore(script, head.firstChild);这句话前增加一个alert;下面的代码才会执行,不增加的话就是空白页面。。。请教了
改为head.appendChild(script, head.firstChild);
(script.onload = script.onreadystatechange = 。。 )这句 和head.appendChild(script, head.firstChild); (head.insertBefore(script, head.firstChild); )这句换个顺序!
setTimeout(funtion(){ head.insertBefore(script, head.firstChild);},10)