Javascript 使用jquery动态删除表行不会';行不通
此表正在动态生成Javascript 使用jquery动态删除表行不会';行不通,javascript,jquery,Javascript,Jquery,此表正在动态生成 <table class='myTab' id='selectPlaceTable' border='1px'> <tr> <td>Something</td> <td>Something</td> <td>Something</td> <td><input type='button' class='buttonRmv' id
<table class='myTab' id='selectPlaceTable' border='1px'>
<tr>
<td>Something</td>
<td>Something</td>
<td>Something</td>
<td><input type='button' class='buttonRmv' id='buttonRmv' value='+'</td>
</tr>
</table>
请尝试以下代码:
$(document).ready(function(){
$('body').on('click',".buttonRmv",function(){
$(this).closest('tr').remove();
});
});
由于要动态生成HTML,请使用事件委派和
.closest()
,如图所示:-
$(document).ready(function(){
$(document.body).on('click',".buttonRmv",function(){
$(this).closest('tr').remove();
});
});
用这个
试试这个:
$(document).ready(function(){
$('body').on('click',".buttonRmv",function(){
$(this).closest('tr').remove();
});
});
试试这个$(this.parent(“td”).parent(“tr”).remove();
$(document).ready(function(){
$(document.body).on('click',".buttonRmv",function(){
$(this).parent().parent().remove();
});
});
$(document).ready(function(){
$('body').on('click',".buttonRmv",function(){
$(this).closest('tr').remove();
});
});