< table >
< tbody >
< tr >
< td > 这行原来就有 </ td >
< td >< button class = " del " > 删除 </ button ></ td >
</ tr >
< tr >
< td > 这行原来就有 </ td >
< td >< button class = " del " > 删除 </ button ></ td >
</ tr >
</ tbody >
</ table >
用jquery动态的给button加上click事件,并且能够删除行。
哥哥们,怎么做?
< tbody >
< tr >
< td > 这行原来就有 </ td >
< td >< button class = " del " > 删除 </ button ></ td >
</ tr >
< tr >
< td > 这行原来就有 </ td >
< td >< button class = " del " > 删除 </ button ></ td >
</ tr >
</ tbody >
</ table >
用jquery动态的给button加上click事件,并且能够删除行。
哥哥们,怎么做?
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.1/jquery.min.js"></script>
<table>
<tbody>
<tr>
<td>这行原来就有</td>
<td><button class="del">删除</button></td>
</tr>
<tr>
<td>这行原来就有</td>
<td><button class="del">删除</button></td>
</tr>
</tbody>
</table>
<script>
$('button.del').live('click', function(){
$(this).parents('tr').remove();
})
</script>
//已有删除按钮初始化绑定删除事件
$(".del").click(function () {
$(this).parents("tr").remove();
});我的没效果啊??高手看下代码有错吗?
$(this).parents('tr').remove();
})
动态添加的dom,用live来绑定事件
//已有删除按钮初始化绑定删除事件
$(".del").click(function () {
$(this).parents("tr").remove();
});有错吗?我看不错来啊!
$(this).parents('tr').remove();
})
楼主 近视很严重?
<tbody>
<tr>
<td> 这行原来就有 </td >
<td><button class = "del"> 删除 </button></td>
</tr>
<tr>
<td> 这行原来就有 </td>
<td><button class = "del" > 删除 </button></td>
</tr>
</tbody>
</table>
<script>
// $('.del').live('click', function () {
// $(this).parents('tr').remove();
// })
$('.del').click(function () {$(this).parents('tr').remove();
</script>这个用你给的代码可以,我注释掉你的代码,用下面的jquery代码就不行了。不明白!