Javascript 我需要实时过滤表单元格(在html jQuery中)

Javascript 我需要实时过滤表单元格(在html jQuery中),javascript,jquery,html,filter,Javascript,Jquery,Html,Filter,搜索堆栈溢出我能够实时过滤行,但我需要更具体。 现在我正在使用以下代码: HTML: 基于此的脚本: 我想做的是能够有4个不同的输入,每个输入过滤每行的第一、第二、第三和第四个单元格(能够按标题、作者、年份和最高价格过滤)。 我怎样才能完成这项工作呢?多亏了Black和Angelcat的链接,我总算把一些东西拼凑起来了 HTML: Título: 自动: 阿诺: 普里西奥·马西莫: JavaScript: function filter(x, y) { // Declare variabl

搜索堆栈溢出我能够实时过滤行,但我需要更具体。 现在我正在使用以下代码:

HTML:

基于此的脚本:

我想做的是能够有4个不同的输入,每个输入过滤每行的第一、第二、第三和第四个单元格(能够按标题、作者、年份和最高价格过滤)。
我怎样才能完成这项工作呢?

多亏了Black和Angelcat的链接,我总算把一些东西拼凑起来了

HTML:

Título:
自动:
阿诺:
普里西奥·马西莫:
JavaScript:

function filter(x, y) {
  // Declare variables 
  var input, filter, table, tr, td, i;
  input = x;
  filter = input.value.toUpperCase();
  table = document.getElementById("catalogo");
  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")[y];
    if (td) {
      if (td.innerHTML.toUpperCase().indexOf(filter) > -1) {
        tr[i].style.display = "";
      } else {
        tr[i].style.display = "none";
      }
    } 
  }
}

function filterNum(x, y) {
  // Declare variables 
  var input, filter, table, tr, td, i;
  input = x;
  if(input.value === "") {
      filter = 0.;
  } 
  else filter = parseFloat(input.value);
  table = document.getElementById("catalogo");
  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")[y];
    if (td) {
      if ((filter >= parseFloat(td.innerHTML)) || filter === 0) {
        tr[i].style.display = "";
      } else {
        tr[i].style.display = "none";
      }
    } 
  }
}
函数过滤器(x,y){
//声明变量
var输入、过滤器、表格、tr、td、i;
输入=x;
filter=input.value.toUpperCase();
table=document.getElementById(“catalogo”);
tr=table.getElementsByTagName(“tr”);
//循环遍历所有表行,并隐藏与搜索查询不匹配的行
对于(i=0;i-1){
tr[i].style.display=“”;
}否则{
tr[i].style.display=“无”;
}
} 
}
}
函数过滤器num(x,y){
//声明变量
var输入、过滤器、表格、tr、td、i;
输入=x;
如果(input.value==“”){
过滤器=0。;
} 
else filter=parseFloat(input.value);
table=document.getElementById(“catalogo”);
tr=table.getElementsByTagName(“tr”);
//循环遍历所有表行,并隐藏与搜索查询不匹配的行
对于(i=0;i=parseFloat(td.innerHTML))| | filter==0){
tr[i].style.display=“”;
}否则{
tr[i].style.display=“无”;
}
} 
}
}
希望这也能帮助其他人

$(document).ready(function(){
    var $rows = $('#catalogo tbody tr');
    $rows.splice(0,1);
    $('#search').keyup(function() {
      var val = $.trim($(this).val()).replace(/ +/g, ' ').toLowerCase().split(' ');

      $rows.hide().filter(function() {
        var text = $(this).text().replace(/\s+/g, ' ').toLowerCase();
        var matchesSearch = true;
        $(val).each(function(index, value) {
          matchesSearch = (!matchesSearch) ? false : ~text.indexOf(value);
        });
        return matchesSearch;
      }).show();
});
});
<label class = "text">Título:<input type="text" id="stitulo" onkeyup="filter(this, 0)" style="margin: 0 auto;"/></label>
<label class = "text">Autor:<input type="text" id="sautor" onkeyup="filter(this, 1)" style="margin: 0 auto;"/></label>
<label class = "text">Año:<input type="text" id="sano" onkeyup="filter(this, 3)" size="1" style="margin: 0 auto;"/></label>
<label class = "text">Precio máximo:<input type="text" id="sprecio" onkeyup="filterNum(this, 4)" size="1" style="margin: 0 auto;"/></label>
function filter(x, y) {
  // Declare variables 
  var input, filter, table, tr, td, i;
  input = x;
  filter = input.value.toUpperCase();
  table = document.getElementById("catalogo");
  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")[y];
    if (td) {
      if (td.innerHTML.toUpperCase().indexOf(filter) > -1) {
        tr[i].style.display = "";
      } else {
        tr[i].style.display = "none";
      }
    } 
  }
}

function filterNum(x, y) {
  // Declare variables 
  var input, filter, table, tr, td, i;
  input = x;
  if(input.value === "") {
      filter = 0.;
  } 
  else filter = parseFloat(input.value);
  table = document.getElementById("catalogo");
  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")[y];
    if (td) {
      if ((filter >= parseFloat(td.innerHTML)) || filter === 0) {
        tr[i].style.display = "";
      } else {
        tr[i].style.display = "none";
      }
    } 
  }
}