<html>  
 <head> 
 <script type="text/javascript"> 
  function insRow(){ 
  var aa=document.getElementById("myTable").insertRow(myTable.rows.length);
var x=aa.insertCell(0);
var y=aa.insertCell(1);//我增加了一行,这里不应该是0吗,为什么是1
x.innerHTML="当减肥考虑的";
y.innerHTML="山东份额";
     //aa.innerHTML="<td>地方考虑的</td><td>222222</td>";//为什么我把上面4行去了,用这个在IE8不行,火狐可以?
 }   
</script>  
 </head> 
  <body>  
 <table id="myTable" border="1">    
 <tr>  
  <td>Row2 cell1</td> 
  <td>Row2 cell2</td> 
 </tr>  
 </table>   
<br/>  
  <input type="button" onclick="insRow()" value="增加一行">   
</body>  
</html>

解决方案 »

  1.   

    上面的代码是说当点击“增加一行”按钮  会在原有表中增加一行; var x=aa.insertCell(0);
     var y=aa.insertCell(1);
    这代码是指:在新增加行中添加两个单元格;
      

  2.   

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>无标题文档</title>
    </head><body>
    <table id="a">
         <tr></tr>
            <tr></tr>
        </table>
        <input type="button" value="click" id="c" onclick="c()" />
        <script>
         //add row
    function c(){
            tbl = document.getElementById("a");
            rowsLen = tbl.rows.length;
            row = tbl.insertRow(rowsLen);        
            
            //create head tag
            textNode = document.createTextNode('1111');        
            cell = row.insertCell(0)//表示列,从0开始,要是加两列,就是row.insertCell(0),row.insertCell(1)
            cell.setAttribute("hight","22");
            cell.appendChild(textNode);        
            row.appendChild(cell); 

    tbl.appendChild(row);
    }
        </script>
    </body>
    </html>
      

  3.   

    insertCell(i) 表示插入第几个单元格
      

  4.   

     //aa.innerHTML="<td>地方考虑的</td><td>222222</td>";//为什么我把上面4行去了,用这个在IE8不行,火狐可以?
    这个呢?
      

  5.   


    在IE中使用如下语句:table.innerHTML = content; 动态修改table的HTML内容时,出现“未知运行错误”。
    错误原因:
         在IE浏览器中,table的innerHTML属性是只读的,不能更改。类似的还有THEAD、TFOOT和TR(唯一例外的是td)。