我找不到有关如何为 Twitter Bootstrap 创建简单搜索查询或行过滤器的教程。我已经尝试了很多,我不确定是我做错了什么还是插件与 Bootstrap 不兼容。如果可以的话请帮忙。
我试过:
$(document).ready(function() {
//Declare the custom selector 'containsIgnoreCase'.
$.expr[':'].containsIgnoreCase = function(n,i,m){
return jQuery(n).text().toUpperCase().indexOf(m[3].toUpperCase())>=0;
};
$("#search").keyup(function(){
$("#tabela").find("tr").hide();
var data = this.value.split(" ");
var jo = $("#tabela").find("tr");
$.each(data, function(i, v){
//Use the new containsIgnoreCase function instead
jo = jo.filter("*:containsIgnoreCase('"+v+"')");
});
jo.show();
}).focus(function(){
this.value="";
$(this).css({"color":"black"});
$(this).unbind('focus');
}).css({"color":"#C0C0C0"});
});
没有这个......也许我在我的表格或搜索框中丢失了任何“id”,我是新手。
最佳答案
这是我使用的:
$('input.filter').live('keyup', function() {
var rex = new RegExp($(this).val(), 'i');
$('.searchable tr').hide();
$('.searchable tr').filter(function() {
return rex.test($(this).text());
}).show();
});
要使用它,您只需创建一个表,其中包含一个类为“searchable”的 tbody,然后在您的页面某处输入一个类为“filter”的输入(我更喜欢将它们放在搜索图标后面的 Bootstrap Popup 中) .
关于html - Twitter Bootstrap 行过滤器/搜索框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14713622/