如何删除表格行的点击?
这是一个小提琴。
我只想删除其中嵌套del链接的行,而不是脚本现在正在执行的最后一行。
单击按钮调用delTableRow()函数,该函数需要更改为删除嵌套的del链接行。
<script type="text/javascript" src="http://code.jquery.com/jquery-latest.min.js"></script>
<script type="text/javascript">
function addTableRow(jQtable){
jQtable.each(function(){
var tds = '<tr>';
jQuery.each($('tr:last td', this), function() {tds += '<td>'+$(this).html()+'</td>';});
tds += '</tr>';
if($('tbody', this).length > 0){$('tbody', this).append(tds);
}else {$(this).append(tds);}
});
}
function delTableRow(jQtable){
jQtable.each(function(){
$('tr:last', this).remove();
});
}
</script>
<table width="100%" border="1" cellspacing="0" cellpadding="0" id="mans">
<tr>
<td>11</td>
<td>12</td>
<td>13</td>
<td><a onclick="delTableRow($('#mans'));" href="#">del</a></td>
</tr>
<tr>
<td>21</td>
<td>22</td>
<td>23</td>
<td><a onclick="delTableRow($('#mans'));" href="#">del</a></td>
</tr>
<tr>
<td>31</td>
<td>32</td>
<td>33</td>
<td><a onclick="delTableRow($('#mans'));" href="#">del</a></td>
</tr>
</table>发布于 2013-03-18 10:16:56
删除onclick并用类替换(即。Class=“删除”)。将事件绑定到表中--这将使您获得比拥有大量事件处理程序更好的性能,并确保添加的新行也将服从这种行为。
$('table').on('click','tr a.remove',function(e){
e.preventDefault();
$(this).closest('tr').remove();
});发布于 2013-03-18 10:14:49
删除所有内联javascript并使用单击事件.不需要在攻击中调用onclick事件。这应该会点着他的诡计。$(this).parents('tr').remove();
尝尝这个
<script type="text/javascript" src="http://code.jquery.com/jquery-latest.min.js"> </script>
<script type="text/javascript">
$(function(){
$('table').on('click','tr a',function(e){
e.preventDefault();
$(this).parents('tr').remove();
});
});
</script>
<table width="100%" border="1" cellspacing="0" cellpadding="0" id="mans">
<tr>
<td>11</td>
<td>12</td>
<td>13</td>
<td><a href="#">del</a></td>
//---^---here remove the onclick inline function for all..
</tr>
....
</table>发布于 2013-03-18 10:12:20
$('td a').on('click',function(e){
//delete code.
e.preventDefault();
$(this).parent().parent().remove(); // OR $(this).parents('tr').remove();
});https://stackoverflow.com/questions/15474139
复制相似问题