日期:2014-05-17  浏览次数:20429 次

js新建行后获取行Index还是原来的行Index
本帖最后由 gaomeng320 于 2013-11-04 10:22:54 编辑
问题是这样 不用js新建行的时候点删除按钮获取的行Index是1,新建行之后点删除按钮获取的行Index还是1
求解决谢谢

页面结构是这样

<table id="tb_ConfModerator" class="table table-hover">
<thead>
<tbody>
<tr><td></td></tr>
<tr>
   <td>
      <div><input type='button' value='删除' onclick="clickbutton(this)"/></div></td>
</tr>
<tr><td></td></tr>
</tbody>
</table>


我的js代码是这样,不用js新建行的时候获取行Index是正确的,js新建完了一行之后获取的Index还是原来的Index

function clickbutton(obj){
trSeq = $(obj).parent().parent().parent().parent().find("tr").index($(obj).parent().parent().parent()[0]);
alert(trSeq);
}


我用js新建行是这样的

var newRow = "<tr><td>111</td></tr>";
$('#tb_ConfModerator tbody').before(newRow);



------解决方案--------------------
$('#tb_ConfModerator tbody').before(newRow);

应该是这个的问题
应该用append