按列值筛选表行 jQuery tablesearch.js

  • 源码大小:27.79KB
  • 所需积分:1积分
  • 源码编号:19JP-3237
  • 浏览次数:301次
  • 最后更新:2023年05月21日
  • 所属栏目:表格
本站默认解压密码:19jp.com 或 19jp_com

简介

tablesearch.js是一个超轻量级的jQuery表过滤器插件,用于在用户在搜索字段中输入术语时过滤表行。它还允许您设置多个过滤器,以便进一步缩小搜索结果的范围。

如何使用它:

1.下载插件,在最新的jQuery库之后加载tablesearch.js库。

<script src="/path/to/cdn/jquery.slim.min.js"></script>
<script src="/path/to/tablesearch.js"></script>

2.启用搜索字段来过滤整个HTML表。

<input type="text" class="myInput" onkeyup="searchTable(this.value, 'list')" placeholder="Search full table..." title="Search" />
<table id="example">
  <thead>
    <tr>
    <th>Firstname</th>
    <th>Lastname</th>
    <th>Email</th>
    </tr>
  </thead>
  <tbody>
    ...
  </tbody>
</table>

3.启用搜索字段以筛选特定表列中的数据。

<!-- Column 1 -->
<input type="text" class="myInput" onkeyup="searchTable(this.value, 'list', 0)" placeholder="Search firstnames..." title="Search">

<!-- Column 2 -->
<input type="text" class="myInput" onkeyup="searchTable(this.value, 'list', 1)" placeholder="Search lastnames..." title="Search">

<!-- Column 3 -->
<input type="text" class="myInput" onkeyup="searchTable(this.value, 'list', 2)" placeholder="Search emails..." title="Search">

预览截图