首页 新闻 会员 周边 捐助

请教个动态创建JS的问题。。

0
[待解决问题]

请教个问题,这是我的代码:

            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;下面的代码才会执行,不增加的话就是空白页面。。。请教了

菜光的主页 菜光 | 初学一级 | 园豆:108
提问于:2011-04-20 14:01
< >
分享
所有回答(2)
0

改为head.appendChild(script, head.firstChild);  

(script.onload = script.onreadystatechange = 。。 )这句 和head.appendChild(script, head.firstChild);  (head.insertBefore(script, head.firstChild); )这句换个顺序!

爱研究源码的javaer | 园豆:930 (小虾三级) | 2011-04-20 14:56
0

setTimeout(funtion(){  head.insertBefore(script, head.firstChild);},10)

小小刀 | 园豆:1991 (小虾三级) | 2011-05-07 10:32
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册