【问题标题】:filter the html table data using jquery使用jquery过滤html表数据
【发布时间】:2015-12-17 19:17:28
【问题描述】:
<table class="table table-hover">
                <thead>
                <tr><th> Block</th>
                    <th>Size</th></tr>

                </thead>
                <tbody id="poolTable" class="tbody">
                <tr>
                    <td>78</td>
                    <td>18</td>

               </tr>
                <tr>
                    <td>52</td>
                    <td>21</td>

               </tr>
                 <tr>
                    <td>54</td>
                    <td>19</td>
                  </tr>

                </tbody>
            </table>

您好,我想使用 jquery 过滤 html 表格数据, 谁能尝试解决这个问题!!

【问题讨论】:

  • 你的问题是什么??
  • 人们不应该写你的解决方案,你应该写你尝试过的和你的问题是什么,人们会帮助你
  • 你的问题不清楚。请更新它。
  • 脚本为$('#btnFilter').click(function(){ var x = $('#filter').val(); console.log(x); });
  • 您认为这会如何工作?我应该在 id="filter" 的输入中插入什么?

标签: javascript jquery html filter


【解决方案1】:

你可以试试这个

https://sunnywalker.github.io/jQuery.FilterTable/

这是一个 jQuery 插件,可让您过滤表格。

【讨论】:

    【解决方案2】:
    function filter(){
        var text = $('#search').val();
    
        $('#poolTable tr').show();
        if (text != "")  {
            $('#poolTable tr td.number').each(function() {
                if ($(this).text().indexOf(text) >= 0) {
                   $(this).parent().show();
                   return true;
                } else {
                   $(this).parent().hide();
                }
            });
    

    这行得通。这里的数字是td 的类名。它只过滤单列。

    【讨论】:

      【解决方案3】:

      请尝试下面的 JavaScript 以获取每个 td 的内容

      $("#filter").keyup(function(){
          var filter = $(this).val();
          $("#poolTable > tr").each(function(e){
      
              cells = this.cells;
              for(i=0; i< cells.length; i++){
                 alert(cells[i].innerHTML);
              }
      
          });
      })
      

      【讨论】:

      • 它不会做这样的事情
      • 在这种情况下,lenght 的值是多少
      猜你喜欢
      • 1970-01-01
      • 2012-02-24
      • 1970-01-01
      • 1970-01-01
      • 2018-04-20
      • 1970-01-01
      • 2018-03-04
      • 1970-01-01
      相关资源
      最近更新 更多