首页 > 其他 > 详细

添加减少表格列

时间:2016-03-18 10:39:40      阅读:280      评论:0      收藏:0      [点我收藏+]

<html>
<head>
<title></title>
<script src="jquery-1.7.2.min.js" type="text/javascript"></script>
<script type="text/javascript">
function addCol() {
$th = $("<th>增加的列头</th>");
$col = $("<td>增加的列</td>");
$("#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();
}

</script>
</head>
<body>
<input id="Button1" type="button" onclick="addCol()" value="增加列" />
<input id="Button2" type="button" onclick="delCol()" value="减少列" />
<table id="tab1" border="1" style="width: 200px;">
<thead>
<tr>
<th>
&nbsp;
Id</th>
<th>
&nbsp;
Name</th>
</tr>
</thead>
<tbody>
<tr>
<td>
&nbsp;
1</td>
<td>
&nbsp;
叶子</td>
</tr>
<tr>
<td>
&nbsp;
2</td>
<td>
&nbsp;
王子</td>
</tr>
</tbody>
</table>
</body>
</html>

添加减少表格列

原文:http://www.cnblogs.com/chai-blogs/p/5291085.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!