`

js table 行数|js table row|js table td|js 操作Table

IE 
阅读更多
兼容FF,IE的table属性操作,
  1,得到表格的行数与某行列数。
      var table=document.getElementById("table");
      alert(gridKPI.rows.length);//得到table的行数
      for(var i=0;i<gridKPI.rows.length;i++)
      {
         alert(gridKPI.rows[i].cells.length);//得到某一行的TD个数
      }
  2.增加一行
      var newTr = table.insertRow();
  3.增加单元格
      var newTd0 = newTr.insertCell();
      var newTd1 = newTr.insertCell();
  4.操作单元格
      newTd0.innerHTML = '<input type=checkbox id="box4">';
      newTd1.innerText= '新加行';
  5.删除行
      var table = document.getElementById("table");
      if (table.rows.length > 1) {
          table.deleteRow(1);
        }
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics