html table相关操作

本文介绍如何使用JavaScript操作HTML表格,包括获取表格的行数、列数、单元格值,以及如何插入和删除表格行。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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);
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值