1

#exceptions是一个html表。我尝试运行下面的代码,但它不会删除表格行。

$('#exceptions').find('tr').each(function(){
    var flag=false;
    var val = 'excalibur';
    $(this).find('td').each(function(){
        if($(this).text().toLowerCase() == val) 
            flag = true;
    });
    if(flag)
        $(this).parent().remove($(this));
});

正确的方法是什么?

4

2 回答 2

1

有没有flagtrue?试试看alert。还有一种不那么复杂的移除元素的方法:

if(flag)
    $(this).remove();
于 2010-06-16T14:53:02.607 回答
1

假设变量标志曾经评估为真,我想你可能只想做......

$(this).remove();

代替...

$(this).parent().remove($(this));
于 2010-06-16T14:54:18.510 回答