本文实例讲述了jQuery增加与删除table列的方法。分享给大家供大家参考,具体如下:
先来看看运行效果图:
完整代码如下:
/p>
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
function addCol() {
$th = $("
增加的列头");$col = $("
增加的列");$("#tab1>thead>tr").append($th);
$("#tab1>tbody>tr").append($col);
}
function delCol() {
//移除最后一列
$("#tab1 tr :last-child").remove();
//移除第一列
//$("#tab1 tr :first-child").remove();
//移除指定的列, 注:这种索引从1开始
//$("#tab1 tr :nth-child(2)").remove();
//移除第一列之外的列
//$("#tab1 tr :not(:nth-child(1))").remove();
}
// -->
Id
Name
1
叶子
2
王子
希望本文所述对大家jQuery程序设计有所帮助。