html - Twitter Bootstrap 行过滤器/搜索框

标签 html twitter-bootstrap search filter

我找不到有关如何为 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/

相关文章:

html - 将导航栏中的 div 垂直居中并向右定位

css - 使用Bootstrap创建固定的页脚

database - Lucene 查询语法搜索

html - 如果 float 元素在 HTML 结构中定义在它们之后,为什么它们不会与 block 元素重叠?

javascript - 在一行后面滑动多个 div 时出现屏蔽问题

twitter-bootstrap - Bootstrap + packery

linux - 搜索包含在 file1 中但在 file2 中找不到的字符串

c++ - 搜索二进制值

html - 摆脱图库中的空白

css - 推特 Bootstrap 3 : Navbar changes width when affix fires