Javascript 根据条件从Html表中删除一行

Javascript 根据条件从Html表中删除一行,javascript,jquery,html,html-table,Javascript,Jquery,Html,Html Table,我有一个html表格 <TABLE id="dlStdFeature" Width="300" Runat="server" CellSpacing="0" CellPadding="0"> <TR> <TD id="stdfeaturetd" vAlign="top" width="350" runat="server"></TD> </TR> </TABLE> 这里的值是文本..需要匹配..如果存在,则

我有一个html表格

<TABLE id="dlStdFeature" Width="300" Runat="server" CellSpacing="0" CellPadding="0">
  <TR>
    <TD id="stdfeaturetd" vAlign="top" width="350" runat="server"></TD>
  </TR>
</TABLE>
这里的值是文本..需要匹配..如果存在,则需要删除该行,,

像这样尝试

function RemoveFromTable(tblID, VALUE)
{
   If(row value = VALUE)
   {
      $("TR[id="+VALUE+"]").hide();  //Assumes that VALUE is the id of tr which you want to remove it
   }
}
您也可以。像这样删除()

像这样试试

function RemoveFromTable(tblID, VALUE)
{
   If(row value = VALUE)
   {
      $("TR[id="+VALUE+"]").hide();  //Assumes that VALUE is the id of tr which you want to remove it
   }
}
您也可以。像这样删除()


我强烈建议在您的案例中使用ViewModel。因此,您可以动态地将数据绑定到表,并有条件地将其格式化为您喜欢的格式。看看Knockout.js:

我强烈建议在您的案例中使用ViewModel。因此,您可以动态地将数据绑定到表,并有条件地将其格式化为您喜欢的格式。看看Knockout.js:

试试这个

function RemoveFromTable(tblID, VALUE){
   $("#"+tblID).find("td:contains('"+VALUE+"')").closest('tr').remove();
}
希望它能起作用

试试这个

function RemoveFromTable(tblID, VALUE){
   $("#"+tblID).find("td:contains('"+VALUE+"')").closest('tr').remove();
}

希望它能工作

使用jquery从HTML表中删除不包含特定文本或字符串的行。

注意:若HTML表中只有两列,我们可以使用“LastChild”属性来查找

*$(document).ready(function(){
$("#tabledata tbody .mainTR").each(function(){
    var lastTD = $(this).find("td:last-child");
    var lastTdText = lastTD.text().trim();
    if(!lastTdText.includes("DrivePilot")){
        $(this).remove();
    }
});
}))

注意:如果HTML表中有两列以上,我们可以使用“第n个子(2)”属性来查找

*$(document).ready(function(){
$("#tabledata tbody .mainTR").each(function(){
    var lastTD = $(this).find("td:last-child");
    var lastTdText = lastTD.text().trim();
    if(!lastTdText.includes("DrivePilot")){
        $(this).remove();
    }
});
使用“第n个子项(列索引)”传递列索引

}))


注意:“DrivePilot”只不过是文本或字符串

使用jquery从HTML表中删除不包含特定文本或字符串的行。

注意:若HTML表中只有两列,我们可以使用“LastChild”属性来查找

*$(document).ready(function(){
$("#tabledata tbody .mainTR").each(function(){
    var lastTD = $(this).find("td:last-child");
    var lastTdText = lastTD.text().trim();
    if(!lastTdText.includes("DrivePilot")){
        $(this).remove();
    }
});
}))

注意:如果HTML表中有两列以上,我们可以使用“第n个子(2)”属性来查找

*$(document).ready(function(){
$("#tabledata tbody .mainTR").each(function(){
    var lastTD = $(this).find("td:last-child");
    var lastTdText = lastTD.text().trim();
    if(!lastTdText.includes("DrivePilot")){
        $(this).remove();
    }
});
使用“第n个子项(列索引)”传递列索引

}))


注意:“DrivePilot”只不过是文本或字符串

Hello。一条线对你有什么价值?您会说id还是标题?我也不建议删除该行(操作DOM很麻烦)。也许仅仅隐藏它就足够了?值是文本,它需要匹配从javascript函数Hello调用RemoveFromTable()的方式。一条线对你有什么价值?您会说id还是标题?我也不建议删除该行(操作DOM很麻烦)。也许仅仅隐藏它就足够了?值是文本,它需要匹配从javascript函数调用RemoveFromTable()的方式