我的页面上有一个表格,上面还有一个过滤文本框,使用以下JQuery进行过滤,效果非常好:
$("#searchInputCompanies").keyup(function () {
//split the current value of searchInput
var data = this.value.split(" ");
//create a jquery object of the rows
var jo = $("#cBody").find("tr");
if (this.value == "") {
jo.show();
return;
}
//hide all the rows
jo.hide();
//Recusively filter the jquery object to get results.
jo.filter(function(i, v) {
var $t = $(this);
for (var d = 0; d < data.length; ++d) {
if ($t.text().toLowerCase().indexOf(data[d].toLowerCase()) > -1) {
return true;
}
}
return false;
})
//show the rows that match.
.show();
$('#selectAllCompanies').prop('checked', '');
}).focus(function () {
this.value = "";
$(this).css({
"color": "black"
});
$(this).unbind('focus');
}).css({
"color": "#C0C0C0"
});如何设置重置筛选按钮?
发布于 2014-11-21 22:28:00
呃,这是一个非常糟糕的实现:(首先,您需要为$("#searchInputCompanies")更改事件,使其变得更容易一些。因此,它将成为$("#searchInputCompanies").on("input", function() {...
$("#resetAction").on("whatEventYouWant", function() {
$("#searchInputCompanies").val("").trigger("input");
});这将在input上触发$("#searchInputCompanies")事件,并且由于文本框为空,所有行都将变为可见的。
https://stackoverflow.com/questions/27071349
复制相似问题