【发布时间】:2020-12-08 15:50:20
【问题描述】:
我有一个简单的 html 表格,其中有一个 <input type="text">
<input class="font-15 w-300-px" id="SomeID" type="text">
<table id="myTable">
<thead>
<tr class="header">
<th style="width:20%;">One</th>
<th style="width:20%;">Two</th>
<th style="width:20%;">Three</th>
<th style="width:20%;">Four</th>
<th style="width:20%;">Five</th>
<th style="width:20%;">Six</th>
</tr>
</thead>
<tbody>
<tr>
<td>
<a href="www.w3school.com" target="_blank">
aaa
</a>
</td>
<td>
<a href="www.idk.com" target="_blank">
bb
</a>
</td>
<td>ccc</td>
<td>dddd</td>
<td>eeee</td>
<td>ffff</td>
</tr>
</tbody>
</table>
然后我有这个过滤脚本。 `
var $rows = $('#myTable tr:gt(0)');
$('#SomeID').keyup(function () {
var val = $.trim($(this).val()).replace(/ +/g, ' ').toLowerCase();
$rows.hide().filter(function () {
var text = $(this).text().replace(/\s+/g, ' ').toLowerCase();
return ~text.indexOf(val);
}).show();
});
我的问题是过滤需要很长时间(我有很多行)。有没有办法只显示 150 行左右?这是解决这个问题的好方法吗?我应该使用其他方式进行过滤吗?谢谢你的一切。
【问题讨论】:
标签: javascript jquery filter html-table