use*_*129 14 html search filter twitter-bootstrap
我很难找到关于如何为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"});
});
Run Code Online (Sandbox Code Playgroud)
没有这个...也许我在我的桌子或搜索框上缺少任何"id",我对此很新.
小智 46
这是我使用的:
$('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();
});
Run Code Online (Sandbox Code Playgroud)
要使用它,你只需要创建一个表,其中tbody为"searchable"类,然后在页面的某个位置输入类"filter"(我更喜欢将它们放在搜索图标后面的Bootstrap Popup中).
Gio*_*TBS 21
这是Filipp Lepalaan提供的解决方案的实例.非常感谢这个小而完美的代码.
$(document).ready(function () {
(function ($) {
$('#filter').keyup(function () {
var rex = new RegExp($(this).val(), 'i');
$('.searchable tr').hide();
$('.searchable tr').filter(function () {
return rex.test($(this).text());
}).show();
})
}(jQuery));
Run Code Online (Sandbox Code Playgroud)
});