日期:2014-05-16 浏览次数:20441 次
<script type="text/javascript">
var rowCount = 0;
function addRow(){
rowCount++;
var rowTemplate = '<tr class="tr_'+rowCount+'"><td>'+rowCount+'</td><td class="cl1"><input type="text" name="Add[]" value="" >'+rowCount+'</td><td class="cl1"><a href="#" onclick=delRow('+rowCount+')>删除</a></td></tr>';
var tableHtml = $("#testTable tbody").html();
tableHtml += rowTemplate;
$("#testTable tbody").html(tableHtml);
}
function delRow(_id){
$("#testTable .tr_"+_id).remove();
rowCount--;
}
</script>
<title>jquery操作表格测试</title>
</head>
<body>
<table id="testTable" border="1" width="500">
<tr>
<td>序号</td>
<td >内容</td>
<td >操作</td>
</tr>
</table>
<input type="button" value="添加行" onclick="addRow();"/>
</body>
$("#testTable tbody").append(rowTemplate);