我如何使用jquery隐藏td元素中的特定单词?

时间:2022-07-07 19:14:30

if i have a table like this

如果我有这样的桌子

<table width="500"  border="0" style="border:0px;" id="options">
<tr>
<td>Designers</td>
<td><input type="checkbox">
</tr>
</table>

how would i hide the row with designers?

我如何与设计师隐藏行?

i was guess it would look something like this

我猜它会看起来像这样

$(document).ready(function() {
  if( $('table #options tr td').html('Designers') {
  $(this).css('display','none');
  }
  });

but am not sure

但我不确定

thanks

2 个解决方案

#1


This should do it, assuming when you said "row" you meant the <tr>, not the <td>:

这应该这样做,假设你说“行”你的意思是,而不是:

$(document).ready(function() {
    $('td', '#options').filter(function() { // select all the TDs
        return $(this).text() == 'Designers'; // keep the ones that have
                                              // 'Designers' as their HTML
    }).each(function() { // loop through each of the ones that matched
        $(this).closest('tr').hide(); // find the parent tr and hide it
    });
});

If you just want to hide the actual <td> (which is not a row, but a cell) then you would do this:

如果你只想隐藏实际的(这不是一行,而是一个单元格)那么你会这样做:

$(document).ready(function() {
    $('td', '#options').filter(function() { // select all the TDs
        return $(this).text() == 'Designers'; // keep the ones that have
                                              // 'Designers' as their HTML
    }).hide();
});

Hiding table cells is in questionable taste, though...

隐藏的桌子细胞味道有问题,但......

#2


$("td:contains('Designers')").hide();

#1


This should do it, assuming when you said "row" you meant the <tr>, not the <td>:

这应该这样做,假设你说“行”你的意思是,而不是:

$(document).ready(function() {
    $('td', '#options').filter(function() { // select all the TDs
        return $(this).text() == 'Designers'; // keep the ones that have
                                              // 'Designers' as their HTML
    }).each(function() { // loop through each of the ones that matched
        $(this).closest('tr').hide(); // find the parent tr and hide it
    });
});

If you just want to hide the actual <td> (which is not a row, but a cell) then you would do this:

如果你只想隐藏实际的(这不是一行,而是一个单元格)那么你会这样做:

$(document).ready(function() {
    $('td', '#options').filter(function() { // select all the TDs
        return $(this).text() == 'Designers'; // keep the ones that have
                                              // 'Designers' as their HTML
    }).hide();
});

Hiding table cells is in questionable taste, though...

隐藏的桌子细胞味道有问题,但......

#2


$("td:contains('Designers')").hide();