【发布时间】:2017-04-15 02:39:32
【问题描述】:
搜索堆栈溢出我能够实时过滤行,但我需要更具体。 现在我正在使用这段代码:
HTML:
<input type="text" id="search" placeholder="Write here to filter">
脚本:
$(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();
});
});
基于此的脚本:How to perform a real time search and filter on a HTML table
我想做的是能够有 4 个不同的输入,每个输入过滤每行的第一、第二、第三和第四个单元格(能够按标题、作者、年份和最高价格进行过滤)。 我怎么能做到这一点?
【问题讨论】:
标签: javascript jquery html filter