【问题标题】:Bootstrap 4 cards filtering with jQuery使用 jQuery 进行 Bootstrap 4 卡片过滤
【发布时间】:2018-04-24 15:15:31
【问题描述】:

以前有人对此进行了挖掘,但我似乎无法使其发挥作用。我正在尝试在 Bootstrap 4 上过滤卡片,当我应用搜索查询时,它最终隐藏了我所有的卡片,而不仅仅是它应该隐藏的卡片。

希望任何人都可以提供帮助。

  $('#search').keyup(function() {
    $('.card').show();
    var filter = $(this).val(); // get the value of the input, which we filter on
    $('.card-deck').find('.card .card-body h4:not(:contains(" + filter + "))').parent().parent().addClass('d-none');
  })

这是完整代码:https://jsfiddle.net/8120104x/#&togetherjs=jTm0prUR4S

【问题讨论】:

  • 小提琴不包括 bootstrap 或 jquery

标签: jquery twitter-bootstrap bootstrap-4


【解决方案1】:

问题是$('.card').show(); 不起作用,因为一旦添加了d-none,它就会覆盖$('.card').show(); 添加的display:block。每个keyup 都应该删除d-none 类...

$('#search').keyup(function (){
    $('.card').removeClass('d-none');
    var filter = $(this).val(); // get the value of the input, which we filter on
    $('.card-deck').find('.card .card-body h4:not(:contains("'+filter+'"))').parent().parent().addClass('d-none');
})

Working demo on Codeply

注意:jQuery :contains is case-sensitive.

【讨论】:

  • 对,这就是它没有意义的原因。如何使查询搜索不敏感?
  • 我会花费数年时间试图解决整个问题。谢谢!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2018-09-21
  • 2017-07-23
  • 1970-01-01
  • 2018-08-06
  • 1970-01-01
  • 2021-12-04
相关资源
最近更新 更多