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