【问题标题】:how to remove a TR which have a TD that contain specific text如何删除具有包含特定文本的 TD 的 TR
【发布时间】:2015-08-11 17:29:46
【问题描述】:

我有以下标记 SPAN >> Table >> TR >> TD:-

现在我想指定使用 css 或 jquery 来删除具有 TD 的 TR,其中包含 <nobr> 标记内的单词“Question”。那么任何人都可以告诉我如何做到这一点吗?谢谢

【问题讨论】:

  • 通过使用 .formtable>tr:nth-child(3) {display:none;}

标签: javascript jquery html css


【解决方案1】:

您可以使用filter比较<nobr>元素的精确文本,然后删除最接近的<tr>

$("span table tr td nobr").filter(function() {
  return $(this).text() === "Question";
}).closest("tr").remove();
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<span>
  <table>
    <tr>
      <td>
        <h3>
          <nobr>Question</nobr>
        </h3>
      </td>
    </tr>
    <tr>
      <td>
        Untouched
      </td>
    </tr>
    
  </table>
</span>

【讨论】:

    【解决方案2】:

    尝试使用:has() 选择器和:contains() selecor 来实现你想要的,

    $("tr:has(td nobr:contains('Question'))").remove();
    

    DEMO

    【讨论】:

      【解决方案3】:

      你可以用 jQuery 来做,如下所示:

      $(document).ready(function(){
          $('td').each(function(){
              if($(this).find('nobr').text() === 'Question') {
                  $(this).closest('tr').remove();
              }
          });
      });
      

      【讨论】:

        【解决方案4】:

        如果您能提供 HTML,那将会很有帮助。我会创建小提琴,但您可以尝试以下解决方案

        在表中迭代 tr 并找到 tr 具有

           $("table.ms-formtable > tbody > tr").each(function(){
               var text = $(this).find("td:first").find("nobr").text();
               if(text === 'Question') {
                  $(this).remove();
               }
           });
        

        http://jsfiddle.net/9tw2kfek/

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 2018-02-28
          • 2012-05-08
          • 2015-05-11
          • 2011-07-09
          • 2016-04-11
          • 1970-01-01
          • 2015-10-28
          相关资源
          最近更新 更多