如屏幕截图所示,我正在使用此 jquery 代码删除表行。
$(":checked").each(function() {
$(this).parent().parent().remove()
});
当我选中标签中的复选框并单击删除时,这第一行也被删除。我使用此代码选择所有复选框 $(":checked") 在第一个复选框之后如何选择?
像这样的东西应该工作:
$(":checked").not(':eq(0)').each(function() {
$(this).parent().parent().remove()
});
试试这个:
$(":checked").filter(":not(:eq(0))").each(function() {
$(this).parent().parent().remove()
});
或者,如果您的表头在thead
标签内,而您的正文在tbody
标签内,您可以使用如下内容:
$("tbody tr :checked").each(function() {
$(this).parent().parent().remove()
});
在第一个复选框上添加一个类,通过该类在单击事件上选中/取消选中所有复选框。
这样,所有其他复选框都将与第一个复选框区分开来。
并使用以下脚本。
$(function() {
$('#test').click(function() {
$(":checked").not('.maincheckbox').each(function() {
$(this).parent().parent().remove()
});
});
});
这是演示:jsfiddle