var script = document.createElement("script");  
script.setAttribute("src","http://www/test.com?r=123");  
script.appendChild(document.createTextNode("test"));  
document.getElementsByTagName("BODY")[0].appendChild(script);  为啥报错!用js加载不成功!

解决方案 »

  1.   

    你用firebug  看一下 你的代码执行了 如果JS内容加载失败,应该是你src的地址不对 
      

  2.   

    没发现什么错误 。
    document.getElementsByTagName("BODY")[0].appendChild(script); 改成head里面 。
    注意js执行顺序 。
      

  3.   

    ie6可以加载啊,只是有一句出错
    var script = document.createElement("script");   
    script.setAttribute("src","http://www/test.com?r=123");   
    document.getElementsByTagName("BODY")[0].appendChild(document.createTextNode("test"));   
    document.getElementsByTagName("BODY")[0].appendChild(script);
      

  4.   

    src  必须是js文件的地址吗?给他一个url不行吗?
      

  5.   

    可以的 。
    script.appendChild(document.createTextNode("test"));    去掉 。
      

  6.   

    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>Insert title here</title>
    <script language="JavaScript">
        var script = document.createElement("script");  
    script.setAttribute("src","http://www.baidu.com");   
    document.getElementsByTagName("body")[0].appendChild(script);  
    </script>
    </head>
    <body></body>
    </html>报错: 网页错误详细信息用户代理: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0; .NET CLR 2.0.50727)
    时间戳: Sat, 16 Apr 2011 01:36:48 UTC
    消息: 'document.getElementsByTagName(...).0' 为空或不是对象
    行: 9
    字符: 2
    代码: 0
    URI: http://www.365wine.com/test.html
      

  7.   

    火狐报错说:document.getElementsByTagName("body")[0] is undefined
      

  8.   


    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>Insert title here</title>
    <script language="JavaScript">
         window.onload = function(){
            var script = document.createElement("script");  
            script.setAttribute("src","http://counter.csdn.net/a/js/AreaCounter.js");  
            document.getElementsByTagName("body")[0].appendChild(script); 
         } 
    </script>
    </head>
    <body>
    </body>
    </html>
    前面就说了 加载顺序 ~
      

  9.   

        nextStep: function(transport){
             var script = document.createElement("script");
             script.setAttribute("src",response.lt_log); 
             document.getElementsByTagName("body")[0].appendChild(script);
    }
    谢谢9楼!我写在JS文件里面好像就不行了!
      

  10.   


    这个改成document.body 试试
      

  11.   

    script.appendChild(document.createTextNode("test")); 去了这个,IE,FF都可能 ,IE我的是IE7
    同时也不知道你这句是做什么的.