当在文本框中输入关键字,就会搜索出包含关键字的数据

实现:

只需要一个内容过滤即可

<body>
  <input type="text" id="searchbox"/>
  <table>
    <tbody>
      <tr>
        <td>aaa</td>
        <td>bbb</td>
      </tr>
      <tr>
        <td>bbb</td>
        <td>ccc</td>
      </tr>
    </tbody>
  </table>
  <script>
    $(function(){
      $('#searchbox').keyup(function(){
        $("table tbody tr").hide()
        .filter(":contains("+($(this).val())+")").show();//filter和contains共同来实现这个功能
      })
    })
  </script>
</body>

 

相关文章:

  • 2021-12-04
  • 2021-08-14
  • 2022-12-23
  • 2021-12-20
  • 2021-06-12
  • 2022-12-23
  • 2021-12-03
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-01-14
  • 2021-08-15
  • 2022-02-08
  • 2022-01-24
相关资源
相似解决方案