Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/blackberry/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jquery 不能正确过滤_Jquery - Fatal编程技术网

Jquery 不能正确过滤

Jquery 不能正确过滤,jquery,Jquery,我试图用jquery进行筛选/搜索,但我的搜索没有给出我想要的结果。首先,这段代码使用细枝来显示数据库中的项目 我的问题是,它只搜索表行的行,例如,如果我搜索标题,则只会显示标题,而不会显示任何其他信息或图像 我希望我的输出像我的 看法 ] 您没有正确使用该函数。函数过滤器需要一个选择器或一个返回布尔值的函数。然后,它将通过只返回函数返回true的元素来减少结果集 如果你想使用这个函数,你需要把你的代码换成这样 $(document).ready(function() { $("#sea

我试图用jquery进行筛选/搜索,但我的搜索没有给出我想要的结果。首先,这段代码使用细枝来显示数据库中的项目

我的问题是,它只搜索表行的行,例如,如果我搜索标题,则只会显示标题,而不会显示任何其他信息或图像

我希望我的输出像我的

看法

]
您没有正确使用该函数。函数过滤器需要一个选择器或一个返回布尔值的函数。然后,它将通过只返回函数返回true的元素来减少结果集

如果你想使用这个函数,你需要把你的代码换成这样

$(document).ready(function() {
    $("#search").on("keyup", function() {
        var value = $(this).val().toLowerCase();
      $('div.product-removal article.product').toggle(true); //Show all products again
      $('div.product-removal article.product').filter(function(index, elem) {
          return $(this).html().toLowerCase().indexOf(value) == -1; //return true when the text is not found
      }).toggle(false); //filter will return all products which does not contain the search query
    });
});
但我觉得你会更喜欢下面的方法

$(document).ready(function() {
    $("#search").on("keyup", function() {
        var value = $(this).val().toLowerCase();
      $('div.product-removal article.product').each(function() {
          $(this).toggle($(this).html().toLowerCase().indexOf(value) > -1);
      });
    });
});

另请注意,我使用了父容器article.product的html属性,而不是单独使用每个元素,因此此代码会不时返回一些误报

您能否执行类似$的简单操作。产品删除:contains+value+。show显示包含搜索值的元素?您可以创建一个fiddle吗?但您不会查看任何内容,因为信息来自database@RafaelCraveiro在浏览器中,您可以检查元素,然后在HTML中查找expandedContent并复制该元素的整个HTML。然后你有我们需要的代码来测试你的问题
$(document).ready(function() {
    $("#search").on("keyup", function() {
        var value = $(this).val().toLowerCase();
      $('div.product-removal article.product').toggle(true); //Show all products again
      $('div.product-removal article.product').filter(function(index, elem) {
          return $(this).html().toLowerCase().indexOf(value) == -1; //return true when the text is not found
      }).toggle(false); //filter will return all products which does not contain the search query
    });
});
$(document).ready(function() {
    $("#search").on("keyup", function() {
        var value = $(this).val().toLowerCase();
      $('div.product-removal article.product').each(function() {
          $(this).toggle($(this).html().toLowerCase().indexOf(value) > -1);
      });
    });
});