我想清除搜索栏。这个想法是在表格中搜索列表。搜索功能从输入中调用 onkeyup 然后我添加了一个图标橡皮擦来清除输入 onclick (span)。
即使清除输入,搜索仍会显示搜索结果列表。我想通过单击橡皮擦图标返回整个列表。有什么建议吗?
function search() {
var input, filter, found, table, tr, td, i, j;
input = document.getElementById("searchInput");
filter = input.value.toUpperCase();
table = document.getElementById("list");
tr = table.getElementsByTagName("tr");
for (i = 0; i < tr.length; i++) {
td = tr[i].getElementsByTagName("td");
for (j = 0; j < td.length; j++) {
if (td[j].innerHTML.toUpperCase().indexOf(filter) > -1) {
found = true;
}
}
if (found) {
tr[i].style.display = "";
found = false;
} else if (!tr[i].id.match('^tableHeader')) {
tr[i].style.display = "none";
}
}
};