<html> 
<head runat="server"> 
    <title>无标题页 </title> 
    <script type="text/javascript"> 
   function Add(){
   var s1=document.createElement("div");
//s1.firstChild.nodeValue="asd";//s1并没有firstChild,所以设置nodeValue这句出错了
//====>
s1.innerHTML="asd";
document.getElementById("div1").appendChild(s1);   }
    
    </script> 
</head> 
<body>       
 <div id="div1"></div>
<input type="button" onclick="Add()" value="添加" />
</body> 
</html> 

解决方案 »

  1.   

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
    <html>
        <head>
            <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
            <title>Untitled Document</title>
        </head>
        <script language="JavaScript">
            function addNode(){
                var s1 = document.createElement("div");
                s1.innerHTML = "asd";
                document.getElementById("div1").appendChild(s1);
            }
        </script>
        <body>
         <input type="button" value="append" onclick="addNode();">
    <hr>
            <div id="div1">
            </div>
        </body>
    </html>
      

  2.   

    var s1=document.createElement("div");
    s1.id="asd";
    document.getElementById("div1").appendChild(s1);
      

  3.   

    FF和IE都支持的:
    var Z="添加的对象";
    var S="添加的对象位置的前面";
    document.body.insertBefore(Z,S); //就是把Z放在S的前面
      

  4.   

    用jQuery
    $("#dvi1").append("<div>asd</div");
      

  5.   

        var s1 = document.createElement("div");
                s1.innerHTML = "asd";
                document.getElementById("div1").appendChild(s1);
      

  6.   

    var s1 = document.createElement("div"); 
    s1.innerHTML = "asd"; 
    document.getElementById("div1").appendChild(s1);