小编Joe*_*Joe的帖子

如何让javascript搜索表中的多列和多行

我想弄清楚如何使所有 5 列和行都可搜索。目前它仅通过第一列 ( DATE) 进行搜索。有人可以帮我搜索所有的列和行吗?我已经包含了 HTML、CSS 和 javascript,以尝试提供尽可能多的信息。

function myFunction() {
  // Declare variables 
  var input, filter, table, tr, td, i;
  input = document.getElementById("myInput");
  filter = input.value.toUpperCase();
  table = document.getElementById("myTable");
  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")[0];
    if (td) {
      if (td.innerHTML.toUpperCase().indexOf(filter) > -1) {
        tr[i].style.display = "";
      } else {
        tr[i].style.display = "none";
      } …
Run Code Online (Sandbox Code Playgroud)

html javascript

4
推荐指数
1
解决办法
4976
查看次数

标签 统计

html ×1

javascript ×1