本文介绍了Twitter Bootstrap行筛选器/搜索框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法找到有关如何为Twitter Bootstrap创建简单搜索查询或行过滤器的教程。我尝试了很多,我不知道如果我做错了什么,或者插件与Bootstrap不兼容。如果可以的话请帮忙。



我试过:

  $(document).ready (function(){
//声明自定义选择器'containsIgnoreCase'。
$ .expr [':']。containsIgnoreCase = function(n,i,m){
return jQuery n).text()。toUpperCase()。indexOf(m [3] .toUpperCase())> = 0;
};

$(#search)。 (function(){

$(#tabela)。find(tr)。hide();
var data = this.value.split();
var jo = $(#tabela)。find(tr);
$ .each(data,function(i,v){

//使用new containsIgnoreCase function
jo = jo.filter(*:containsIgnoreCase('+ v +'));
});

jo.show(); ();
$(this).css({color:black});
$(this).unbind('focus');
})。css({color:#C0C0C0});
});

没有这个...也许我错过了我的桌子或搜索框上的任何id ,我是新的。

解决方案

这是我使用的:

live('keyup',function(){
var rex = new RegExp($(this).val(), ')';
$('。searchable tr')。hide();
$('。searchable tr')。filter(function(){
return rex.test $(this).text());
))。show();
});

要使用它,只需创建一个表,带有searchable类的tbody,然后在页面上的某处输入filter(我宁愿将它们放在搜索图标后面的Bootstrap Popup中)。

I'm having trouble finding a tutorial on how to create a simple search query, or row filter, for Twitter Bootstrap. I've tried many, I'm not sure if I'm doing something wrong or the plugins are not compatible with Bootstrap. Please help if you can.

I've tried:

$(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"});
});

Nothing with this... Maybe I'm missing any "id" on my table or search box, I'm new with this.

解决方案

Here's what I use:

$('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();
    });

To use it, you just create a table, with a tbody with the class "searchable" and then an input with class "filter" somewhere on your page (I prefer to put them in a Bootstrap Popup behind a search icon).

这篇关于Twitter Bootstrap行筛选器/搜索框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-28 01:03