【问题标题】:Get row from a table by td class and specific value in the cell in jquery通过 td 类和 jquery 单元格中的特定值从表中获取行
【发布时间】:2014-06-28 07:53:21
【问题描述】:

我想在具有类名的隐藏 td 中找到多个表中具有特定值的行

<table>
   <tr>
    <td class="id hidden">16</td>
    <td class="maintenance_date">30 Jun 2014</td>
    <td class="station_code">TSK</td><td class="gear_code">T1</td>
    <td class="role_name">INCHARGE SSE/SE</td>
</tr>
<table>

一个或多个表中会有多行。例如,我希望仅在隐藏类 ID 的 td 上显示文本为 16 的行。

【问题讨论】:

    标签: javascript jquery html


    【解决方案1】:

    很简单:

    var searchTerm = 16;
    var elements = $('td.hidden').filter(function() {
          return $(this).text() == searchTerm;
     }).parent();
    

    【讨论】:

      【解决方案2】:

      你可以使用:

      var td16_row=$('td').filter(function(){
          return $(this).text()=="16";
      }).parent();
      

      【讨论】:

      • 可以返回 tbody
      • @ShivanDragon 那将是一个无效的 html。
      • @ShivanDragon:为什么会返回 tbody。
      • 所以它会返回 tr 而不是 tbody
      • @MilindAnantwar 是的,对不起,我的错误。
      【解决方案3】:

      我想我会做这样的事情(未经测试)

      var elements = $("table tr").find(".id.hidden").html();
      
      $.each( elements, function( key, value ) {
        if (parseInt(value) === 16) {
            //do something with $(this)
        }
      });
      

      【讨论】:

        猜你喜欢
        • 2012-04-20
        • 2018-06-16
        • 2011-10-19
        • 2013-08-01
        • 2013-05-16
        • 1970-01-01
        • 1970-01-01
        • 2012-12-12
        • 1970-01-01
        相关资源
        最近更新 更多