Javascript 多索引表/行搜索

Javascript 多索引表/行搜索,javascript,Javascript,我正在使用W3学校页面中的JavaScript,它提供了一个如何更改要搜索的单个索引的提示,但是如果我要同时循环/搜索该行的多个索引呢 例如,我想同时搜索索引0和1。根据此网站的代码 我按照您的要求修改了代码,您可以同时按姓名和国家进行研究,这里是javascript代码: <script> function myFunction() { var input, filter, table, tr, td, i; input = document.getElementById(

我正在使用W3学校页面中的JavaScript,它提供了一个如何更改要搜索的单个索引的提示,但是如果我要同时循环/搜索该行的多个索引呢


例如,我想同时搜索索引0和1。

根据此网站的代码

我按照您的要求修改了代码,您可以同时按姓名和国家进行研究,这里是javascript代码:

<script>
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];
    td2 = tr[i].getElementsByTagName("td")[1];
    if (td2 || td) {
      if (td2.innerHTML.toUpperCase().indexOf(filter) > -1 || td.innerHTML.toUpperCase().indexOf(filter) > -1)      {
        tr[i].style.display = "";
      } else {
        tr[i].style.display = "none";
      }
    } 
  }
}
</script>

函数myFunction(){
var输入、过滤器、表格、tr、td、i;
输入=document.getElementById(“myInput”);
filter=input.value.toUpperCase();
table=document.getElementById(“myTable”);
tr=table.getElementsByTagName(“tr”);
对于(i=0;i-1 | | td.innerHTML.toUpperCase().indexOf(过滤器)>-1){
tr[i].style.display=“”;
}否则{
tr[i].style.display=“无”;
}
} 
}
}

我希望这就是你想要的

完美答案谢谢!!!如果假设你有10个索引,你知道一种更有效的方法吗?