简体   繁体   English

通过在 td 中搜索确切的文本来删除 tr

[英]to remove tr by searching exact text in td

I have a table in which I have list of name.我有一个表,其中有名称列表。

Now I want to delete it by jquery on basis on its text.现在我想在其文本的基础上通过 jquery 将其删除。

$(addrow + " td:contains(" + foodname + ")").parent('tr').next("tr").remove();

I have this which works fine but it have a flaw.我有这个工作正常,但它有一个缺陷。

For eg for removing 'xyz',例如,用于删除“xyz”,

Case 1: td with text such as xyz,abc,poi etc. ------> it works fine案例 1:带有 xyz、abc、poi 等文本的 td ------> 效果很好

Case 2: td with text such as xyz,abxyzc,poi etc. ------> removes xyz and xyzabc as well案例 2:带有文本的 td,例如 xyz、abxyzc、poi 等 ------> 也删除 xyz 和 xyzabc

Is there a direct way to check exact and not contains in td by jquery?有没有直接的方法来检查 jquery 的 td 中是否包含准确且不包含的内容?

Thank you!谢谢!

match your td text value with text()将您的 td 文本值与text()匹配

Try below code -试试下面的代码 -

If you want to delete tr which is next to that 'tr' in which td matches with the text.如果要删除td与文本匹配的“ tr ”旁边的 tr。

$(addrow).find('td').each(function(){
    if($(this).text() == foodname){
        $(this).parent('tr').next("tr").remove();
    }
});

Or you just want to delete the tr whose td matches with the text.或者您只想删除td与文本匹配的tr

$(addrow).find('td').each(function(){
    if($(this).text() == foodname){
        $(this).parent('tr').remove(); // don't use next() here
    }
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM