清除搜索栏


糖果
2025-03-22 02:07:55 (17天前)

我想清除搜索栏。这个想法是在表格中搜索列表。搜索功能从输入中调用 onkeyup 然后我添加了一个图标橡皮擦来清除输入 onclick (span)。

即使清除输入,搜索仍会显示搜索结果列表。我想通过单击橡皮擦图标返回整个列表。有什么建议吗?

  1. function search() {
  2. var input, filter, found, table, tr, td, i, j;
  3. input = document.getElementById("searchInput");
  4. filter = input.value.toUpperCase();
  5. table = document.getElementById("list");
  6. tr = table.getElementsByTagName("tr");
  7. for (i = 0; i < tr.length; i++) {
  8. td = tr[i].getElementsByTagName("td");
  9. for (j = 0; j < td.length; j++) {
  10. if (td[j].innerHTML.toUpperCase().indexOf(filter) > -1) {
  11. found = true;
  12. }
  13. }
  14. if (found) {
  15. tr[i].style.display = "";
  16. found = false;
  17. } else if (!tr[i].id.match('^tableHeader')) {
  18. tr[i].style.display = "none";
  19. }
  20. }
  21. };
1 条回复
  1. 动动手指,沙发就是你的了!
登录 后才能参与评论