jQuery 表格过滤是一种使用 jQuery 库来动态过滤表格内容的技术。它允许用户通过输入文本来实时显示或隐藏表格中的行,从而提高数据的可查找性。
以下是一个简单的 jQuery 表格过滤示例:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>jQuery Table Filter</title>
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
</head>
<body>
<input type="text" id="filterInput" placeholder="Search...">
<table id="dataTable">
<thead>
<tr>
<th>Name</th>
<th>Age</th>
<th>City</th>
</tr>
</thead>
<tbody>
<tr>
<td>John Doe</td>
<td>28</td>
<td>New York</td>
</tr>
<tr>
<td>Jane Smith</td>
<td>32</td>
<td>Los Angeles</td>
</tr>
<!-- More rows here -->
</tbody>
</table>
<script>
$(document).ready(function() {
$("#filterInput").on("keyup", function() {
var value = $(this).val().toLowerCase();
$("#dataTable tbody tr").filter(function() {
$(this).toggle($(this).text().toLowerCase().indexOf(value) > -1);
});
});
});
</script>
</body>
</html>
通过以上方法,可以有效地实现和维护 jQuery 表格过滤功能,提升用户界面的交互性和实用性。
领取专属 10元无门槛券
手把手带您无忧上云