확인란을 사용하여 필터링하려고합니다. 하지만 문제가 있습니다. 제품 카테고리를 선택하면 각 카테고리 항목이 표시되지만 모두 선택 취소하면 제품이 없습니다. 카테고리 항목을 선택 해제하면이 작업을 수행하고 싶습니다. 모든 항목을 표시하고 싶습니다. 어떻게해야합니까? 도와주세요, 제발 ?
<div class="tags">
<label>
<input type="checkbox" rel="arts" />
Arts
</label>
<label>
<input type="checkbox" rel="computers" />
Computers
</label>
<label>
<input type="checkbox" rel="health" />
Health
</label>
<label>
<input type="checkbox" rel="video-games" />
Video Games
</label>
</div>
<ul class="results">
<li class="arts computers">Result 1</li>
<li class="video-games">Result 2</li>
<li class="computers health video-games">Result 3</li>
<li class="arts video-games">Result 4</li>
</ul>
jquery,,
$(document).ready(function () {
$('div.tags').find('input:checkbox').live('click', function () {
$('.results > li').hide();
$('div.tags').find('input:checked').each(function () {
$('.results > li.' + $(this).attr('rel')).show();
});
});
});
jsfiddle로 온라인에서 볼 수 있습니다.
이렇게 해봐
$(document).ready(function () {
$('div.tags').find('input:checkbox').live('click', function () {
if ($(this).prop("checked")) {
$('.results > li').toggle('show');
$('div.tags').find('input:checked').each(function () {
$('.results > li.' + $(this).attr('rel')).toggle('show');
});
} else{
$('.results > li').show();
}
});
});
또한 toggle ( 'show') 좋은 효과를줍니다.
you Can just use Show() and hide() instead of toggle('show')
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다