gpt4 book ai didi

javascript - 搜索分页表 - JS

转载 作者:行者123 更新时间:2023-11-30 20:54:38 24 4
gpt4 key购买 nike

我是 JS 初学者。我的数据库中有一个包含大约 100 条记录的表,但随后,它已被分页为一页上的 10 条记录。当我搜索我的查询时,它不会搜索整个表格,而是搜索当前页面。

请问如何让我的查询搜索整个表格而不是只搜索当前页面?

<script>
function myFunction() {
// Declare variables
var input, filter, table, tr, td, i;
input = document.getElementById("myInput");
filter = input.value.toUpperCase();
table = document.getElementById("table");
tr = table.getElementsByTagName("tr");

// Loop through all table rows, and hide those who don't match the search query
for (i = 0; i < tr.length; i++) {
td = tr[i].getElementsByTagName("td")[1];
if (td) {
if (td.innerHTML.toUpperCase().indexOf(filter) > -1) {
tr[i].style.display = "";
} else {
tr[i].style.display = "none";
}
}
}
}
</script>

最佳答案

如果您使用 jQuery DataTables它可能会使您的任务变得容易得多。否则,我建议您尝试将 tr[i].style.display = ""; 替换为 tr[i].hide()tr[i .show().

关于javascript - 搜索分页表 - JS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47810874/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com