input keyup的时候实现内容过滤

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

实现:

只需要一个内容过滤即可

<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>

 

posted @ 2017-09-09 18:41  rachelch  阅读(349)  评论(0编辑  收藏  举报