jquery:迭代表行时删除表行

时间:2010-06-16 14:50:32

标签: jquery html tablerow

#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));
});

这样做的正确方法是什么?

2 个答案:

答案 0 :(得分:1)

flag是否会转为true?试试alert吧。还有一种不太复杂的删除元素的方法:

if(flag)
    $(this).remove();

答案 1 :(得分:1)

假设变量标志的评估结果为真,我想你可能只想做......

$(this).remove();

而不是......

$(this).parent().remove($(this));