【发布时间】:2021-07-01 03:12:33
【问题描述】:
请告诉我如何将displayCount 函数绑定到当前的filter_item? $('.filter_item').each(function() { 中的所有内容都可以正常工作,但 function displayCount() { 对页面上的所有 filter_item 运行。
jQuery(function($) {
var count = 0;
$('.filter_item').each(function() {
count = $(this).find('input[type=checkbox].jet-checkboxes-list__input:checked').length;
displayCount();
$(this).find('input[type=checkbox].jet-checkboxes-list__input').bind('click' , function(e, a) {
if (this.checked) {
count += a ? -1 : 1;
} else {
count += a ? 1 : -1;
}
displayCount();
});
});
function displayCount() {
if (count == 0) {
$('.count').hide();
} else {
$('.count').show();
$('.count').text(count);
}
}
});
【问题讨论】:
-
你能显示你的html代码吗?