gpt4 book ai didi

javascript - JQuery - 无法使用同位素 js woocommerce 产品进行过滤

转载 作者:行者123 更新时间:2023-11-30 16:29:15 24 4
gpt4 key购买 nike

我已经编写了一个函数来使用同位素 js 过滤 woocommerce 产品。我正在尝试解决问题。但是过滤器不起作用。HTML 看起来像

<div class = "filters">
<input type="checkbox" class = "do_this_filter" value=".Hand-Wash">Hand wash<br>
<input type="checkbox" class = "do_this_filter" value=".Machine-Wash">Machine wash<br>
</div>
<ul class ='products'>
<li class="items Hand-wash"></li>
<li class="items Machine-Wash"></li>
</ul>

我用的jQuery是

$( function() {
// init Isotope
var $grid = $('.products').isotope({
itemSelector: '.item',
layoutMode: 'fitRows'
});

// bind filter click
$('.do_this_filter').on( 'click', function() {
var filterValue = $( this ).val();
// use filterFn if matches value
$grid.isotope({ filter: filterValue });
});
// change is-checked class
$('.do_this_filter').each( function( i, buttonGroup ) {
var $buttonGroup = $( buttonGroup );
$buttonGroup.on( 'click', function() {
$buttonGroup.find('.is-checked').removeClass('is-checked');
$( this ).addClass('is-checked');
});
});

});

这没有用任何人都可以帮忙吗?提前致谢。
Jsfiddle

最佳答案

像这样尝试:

$(function() {
// init Isotope
var $grid = $('.products'),
$checkboxes = $('.filters input');

$grid.isotope({
itemSelector: '.items',
layoutMode: 'fitRows'
});

$checkboxes.change(function() {
var filters = [];
// get checked checkboxes values
$checkboxes.filter(':checked').each(function() {
filters.push(this.value);
});
filters = filters.join(', ');
$grid.isotope({
filter: filters
});
});

});
.items {
width: 100px;
height: 100px;
background: red;
margin: 3px;
list-style: none;
display: inline-block;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery.isotope/2.2.2/isotope.pkgd.min.js"></script>
<div class="filters">
<input type="checkbox" class="do_this_filter" value=".Hand-wash">Hand wash
<br>
<input type="checkbox" class="do_this_filter" value=".Machine-Wash">Machine Wash
<br>
</div>
<ul class='products'>
<li class="items Hand-wash">Demo product1</li>
<li class="items Machine-Wash">Demo product2</li>
</ul>

关于javascript - JQuery - 无法使用同位素 js woocommerce 产品进行过滤,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33584539/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com