是这样的,在第二行有一个按钮点击的时候会吧当前行的上一行也删除,怎么写。有思路,不会写代码
$('tr').click(function(){
$(this).prev().remove()
$(this).remove()
})
是这个效果,点击减号当前行和上面哪一行都删除
$('button').click(function(){
$(this).parent(".td").parent(".tr").prev().remove()
$(this).parent(".td").parent(".tr").remove()
})
找到你要删除的上一个tr节点,将它一起删除就可以了
jquery使用this获取当前标签,若当前标签不是tr标签,使用parent()获取tr,在使用prev()取得上一标签,然后再.remove()删除
<input type="button" value="-" onclick="remove(this)"/>
function remove(btn){
var tr=$(btn).closest('tr');
tr.prev().remove();
tr.remove()
}
$(function(){
$('button').click(function(){
$(this).parent(".td").parent(".tr").prev().remove()
$(this).parent(".td").parent(".tr").remove()
})
});