0

我有一个 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 AddToTable(tblID, value)
{
    var $jAdd = jQuery.noConflict();

    var row= $jAdd("<tr/>").attr("className","lineHeight");
    var cell = $jAdd("<td/>").attr({"align" : "center","width" : "3%"});
    var cell1 = $jAdd("<td/>").html("<b>* </b>" + value);
    row.append(cell);
    row.append(cell1);
    $jAdd(tblID).append(row);
}

现在我想要一个函数从这个表中删除一行,如果值匹配..as

function RemoveFromTable(tblID, VALUE)
{
   If(row value = VALUE)
   {
     remove this row
   }
}

这里 VALUE 是 TEXT ..需要匹配..如果存在需要删除该行,,

4

5 回答 5

4

尝试这个

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

希望它会工作

于 2013-06-07T12:01:23.410 回答
0

像这样试试

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
   }
}

你也可以 。删除()喜欢

$("TR[id="+VALUE+"]").remove();
于 2013-06-07T11:54:06.980 回答
0

我强烈建议在您的情况下使用 ViewModel。因此,您可以将数据动态绑定到表格,并有条件地将其格式化为您喜欢的任何格式。看看 Knockout.js: http: //knockoutjs.com/

于 2013-06-07T11:54:17.147 回答
0
function RemoveFromTable(tblID, VALUE){
   $(tblID).find('td').filter(function(){
     return $.trim($(this).text()) === VALUE;
   }).closest('tr').remove();
}
于 2013-06-07T11:56:32.837 回答
0

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

注意:如果HTML表格中只有两列,我们可以使用“last-child”属性来查找。

*$(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 表格中的列多于两列,我们可以使用“nth-child(2)”属性来查找。

使用“nth-child(列索引)”传递列索引

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

});

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

于 2020-08-24T16:54:06.767 回答