小编Rol*_*ara的帖子

过滤表多列

我在我的页面上使用了w3School代码并且它工作正常,但它只过滤了一列,不知道如何创建循环但跳跃有更容易的解决方案.

    td = tr[i].getElementsByTagName("td")[0];     
Run Code Online (Sandbox Code Playgroud)

改变这里0到1改变列,可以找到任何东西,所以尝试了许多不同的东西但不是程序员不知道是否有任何其他属性允许多列,花了这么多搜索,请帮助

function myFunction() {
  var input, filter, table, tr, td, i;
  input = document.getElementById("myInput");
  filter = input.value.toUpperCase();
  table = document.getElementById("myTable");
  tr = table.getElementsByTagName("tr");
  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)
* {
  box-sizing: border-box;
}

#myInput {
  background-image: url('/css/searchicon.png');
  background-position: 10px 10px;
  background-repeat: no-repeat;
  width: 100%;
  font-size: 16px;
  padding: 12px …
Run Code Online (Sandbox Code Playgroud)

html javascript html-table filter

3
推荐指数
1
解决办法
2万
查看次数

标签 统计

filter ×1

html ×1

html-table ×1

javascript ×1