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);