window.onload=function(){
    
    //创建表
        var ttable = document.createElement("table");
        ttable.setAttribute("border-collapse","1");
        ttable.setAttribute("width","500");
        ttable.setAttribute("cellpadding","3");
        ttable.setAttribute("cellscpaing","0");
        //创建tbody
        var ttbody = document.createElement("tbody");
        ttable.appendChild(ttbody);
        //插入第一行
        ttbody.insertRow(0);
        ttable.rows[0].insertCell(0);
        ttbody.rows[0].cells[0].appendChild(document.createTextNode("1,1"));
        ttbody.rows[0].insertCell(1);       
        ttbody.rows[0].cells[1].appendChild(document.createTextNode("1,2"));
        //插入第二行
        ttbody.insertRow(1);
        ttable.rows[1].insertCell(0);
        ttbody.rows[1].cells[0].appendChild(document.creteTextNode("2,1"));
        ttable.rows[1].insertCell(1);
        ttbody.rows[1].cells[1].appendChild(document.createTextNode("2,2"));
        document.body.appendChild(ttable);
    }

解决方案 »

  1.   

    window.onload=function(){ 
        
        //创建表 
            var ttable = document.createElement("table"); 
            ttable.setAttribute("border-collapse","1"); 
            ttable.setAttribute("width","500"); 
            ttable.setAttribute("cellpadding","3"); 
            ttable.setAttribute("cellscpaing","0"); 
            //创建tbody 
            var ttbody = document.createElement("tbody"); 
            ttable.appendChild(ttbody); 
            //插入第一行 
            ttbody.insertRow(0); 
            ttable.rows[0].insertCell(0); 
            ttbody.rows[0].cells[0].appendChild(document.createTextNode("1,1")); 
            ttbody.rows[0].insertCell(1);      
            ttbody.rows[0].cells[1].appendChild(document.createTextNode("1,2")); 
            //插入第二行 
            ttbody.insertRow(1); 
            ttable.rows[1].insertCell(0); 
            ttbody.rows[1].cells[0].appendChild(document.createTextNode("2,1")); 
            ttable.rows[1].insertCell(1); 
            ttbody.rows[1].cells[1].appendChild(document.createTextNode("2,2")); 
            document.body.appendChild(ttable); 
        }