简体   繁体   English

HTML表上的多个搜索过滤器

[英]Multiple Search Filters on a HTML Table

I was wondering if you would be able to help. 我想知道你是否能够提供帮助。

I have a HTML table and a text field. 我有一个HTML表和一个文本字段。 Javascript on page load takes the value in the text field and filters the table. 页面加载上的Javascript获取文本字段中的值并过滤表格。

I would to like to add a second text field and use that to further filter the table based on the value in the text field. 我想添加第二个文本字段,并使用它来根据文本字段中的值进一步过滤表。

I added a new text field and assigned it a value. 我添加了一个新的文本字段并为其分配了一个值。 I added the same script (I think this is where my problem is) and ameneded to look at the new field. 我添加了相同的脚本(我认为这是我的问题所在),并且考虑了查看新字段。 Now it look's as though it is only using the second script. 现在它看起来好像只使用第二个脚本。

How can I get the both to work and filter the table? 如何让两者都工作并过滤表格? Any ideas? 有任何想法吗?

HTML HTML

 <input type="hidden" id="myInput" value="3"/>
<input type="hidden" id="myInput1" value="Time"/>

JAVASCRIPT JAVASCRIPT

$(document).ready(function() {
                console.log("ready");
  var input, filter, table, tr, td, i, searchFilter;
  input = document.getElementById("myInput");
  filter = input.value.toUpperCase();
  table = document.getElementById("job_table");
  tr = table.getElementsByTagName("tr");

  for (i = 0; i < tr.length; i++) {
    td = tr[i].getElementsByTagName("td")[3];
    if (td) {
        txtValue = td.textContent || td.innerText;
      if (txtValue.toUpperCase().indexOf(filter) > -1) {
        tr[i].style.display = "";
      } else {
        tr[i].style.display = "none";
      }
    }      
  }
});

    $(document).ready(function() {
                console.log("ready");
  var input, filter, table, tr, td, i, searchFilter;
  input = document.getElementById("myInput");
  filter = input.value.toUpperCase();
  table = document.getElementById("job_table");
  tr = table.getElementsByTagName("tr");

  for (i = 0; i < tr.length; i++) {
    td = tr[i].getElementsByTagName("td")[3];
    if (td) {
        txtValue = td.textContent || td.innerText;
      if (txtValue.toUpperCase().indexOf(filter) > -1) {
        tr[i].style.display = "";
      } else {
        tr[i].style.display = "none";
      }
    }      
  }
});
$(document).ready(function() {
            console.log("ready");
      var input, filter, table, tr, td, i, searchFilter;
      let input1 =  document.getElementById("myInput1");
      let filter1;
      input = document.getElementById("myInput");
      filter = input.value.toUpperCase();
      filter1=input1.value.toUpperCase();
      table = document.getElementById("job_table");
      tr = table.getElementsByTagName("tr");
     for (i = 0; i < tr.length; i++) {
       td = tr[i].getElementsByTagName("td")[3];
       if (td) {
        txtValue = td.textContent || td.innerText;
        if (txtValue.toUpperCase().indexOf(filter) > -1 || 
         txtValue.toUpperCase().indexOf(filter1) > -1) {
              tr[i].style.display = "";
            } else {
           tr[i].style.display = "none";
                   }
              }      
          }
      });

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM