<SCRIPT>
andacc('中国');window.onload=function andacc(urr)
{
 
document.getElementById("div").innerHTML=urr; 
}
</SCRIPT><div id="div"></div>为什么不能在<div id="div"></div>中显示中国

解决方案 »

  1.   

    <script type="text/javascript">
    function andacc(urr) {
    document.getElementById("div").innerHTML = urr;
    }
    window.onload = function(){
    andacc("中国");
    };
    </script>
    <div id="div"></div> 
      

  2.   

    <span id="div"></span>
      

  3.   

    因为是脚本先执行了,但执行的时候还没有下面的DIV,这样找不到DIV就报错了。
    所以要把脚本放在最下面
      

  4.   

    <script type="text/javascript">
      

  5.   


      function andacc(urr) {
        document.getElementById("div").innerHTML = urr;
    }  <body onload="andacc("中国");"></body>  <div id="div"></div>
    用jquery 一句话搞定:$(function(){
      $("#div").html("中国");
    })