html jQuery搜索过滤,客户端脚本。您需要向包装元素添加一个数据容器,该数据容器将隐藏在不正确的m上

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了html jQuery搜索过滤,客户端脚本。您需要向包装元素添加一个数据容器,该数据容器将隐藏在不正确的m上相关的知识,希望对你有一定的参考价值。

$('.your-search-box').keyup(function(event) {
  var query = $(this).val().toLowerCase();
  var filter = $('[data-filter]');
  var container = $('[data-container]');

  if ($(this).val().length <= 1) {
    $(filter).each(function() {
      var item = $(this).text().slice(0, 1).toLowerCase();

      if (item != query) {
        $(this).closest(container).hide();
      } else {
        $(this).closest(container).show();
      }
    });
  } else {
    $(filter).show();
    $(filter).each(function() {
      var item = $(this).text().toLowerCase();

      if (item.indexOf(query) == -1) {
        $(this).closest(container).hide();
      } else {
        $(this).closest(container).show();
      }
    });
  }

  if ($(this).val().length === 0) {
    $(filter).show();
    $(container).show();
  }
});
<input type="search" class="your-search-box" value="Match" />

<div data-container>
  <a href="#" data-filter>Match this Text</a>
</div>

<div data-container>
  <a href="#" data-filter>Not any of this</a>
</div>

以上是关于html jQuery搜索过滤,客户端脚本。您需要向包装元素添加一个数据容器,该数据容器将隐藏在不正确的m上的主要内容,如果未能解决你的问题,请参考以下文章

带有输入的 jQuery 过滤器(包括/内部复选框)

没有自动过滤器的jquery移动搜索

带有 LinQ 过滤器和 jQuery tmpl 示例的 jQuery AJAX 请求

jQuery mobile折叠列表视图,搜索不起作用

jQuery Mobile:Listview 过滤器搜索回调函数

jQuery 遍历 – 过滤