日期:2014-05-17  浏览次数:20560 次

html table相关操作
table样例
<table width="98%" border="0" align="center" cellpadding="3" cellspacing="1" class="table4" name='tbl' id="tbl">
	<colgroup>
	<col width="40%"/>
	<col width="15%"/>
	<col width="15%"/>
	<col width="15%"/>
	<col width="15%"/>
	</colgroup>
	<thead>
	    <tr>
	      <th nowrap>标题1</th>
	      <th nowrap>标题2</th>
	      <th nowrap>标题3</th>
	      <th nowrap>标题4</th>
	      <th nowrap>标题4</th>
	    </tr>
    </thead>
    <tbody id="tbody">   
            <tr>
	      <th nowrap>数据1</th>
	      <th nowrap>数据2</th>
	      <th nowrap>数据3</th>
	      <th nowrap>数据4</th>
	      <th nowrap>数据4</th>
	    </tr>
    </tbody>         		
 </table>


1.获取table行数
   $("tbody").rows.length
2.获取table某行里的具体列数
   $("tbody").rows[0].cells.length
3.获取单元格的值
   $("tbody").rows[0].cells[0].innerText
4.插入列
   var R=$("tbody").insertRow();
5.插入单元格
   var cell = R.insertCell()
   C.innerHTML="数据";
6.删除列
   $("tbody").deleteRow(0);