한 페이지에 범주의 모든 제품을 나열하는 상점에 간단한 jQuery 제품 필터를 조합하려고합니다. 상점 설치 방법 때문에 AJAX를 통해 달성 할 수 없습니다.체크 박스를 사용하는 jQuery 제품 필터 및 : contains() show/hide
간단히 말해서 카테고리의 모든 제품이 한 페이지에 있습니다. 그들은 다양한 브랜드 제품 이름과 팀 이름을 가지고 있습니다. 마크 업은 다음과 유사합니다 (마지막의 양식은 필자가 필터를 수행하는 방법입니다).
<div id="CategoryContent">
<ul>
<li class="product">Brand1 PRODUCT1 TeamA</li>
<li class="product">Brand1 PRODUCT2 TeamB</li>
<li class="product">Brand2 PRODUCT3 TeamB</li>
<li class="product">Brand2 PRODUCT4 TeamC</li>
<li class="product">Brand3 PRODUCT5 TeamA</li>
<li class="product">Brand3 PRODUCT6 TeamD</li>
<li class="product">Brand4 PRODUCT7 TeamD</li>
<li class="product">Brand1 PRODUCT8 TeamA</li>
<li class="product">Brand1 PRODUCT9 TeamA</li>
<li class="product">Brand1 PRODUCT10 TeamB</li>
<li class="product">Brand4 PRODUCT11 TeamD</li>
<li class="product">Brand2 PRODUCT12 TeamA</li>
</ul>
<div style="clear:both;"></div>
<div class="filter">
<form id= "brandfilter" action="">
<h2>Brands:</h2>
<input type="checkbox" name="brand" value="Brand1"/>Brand1 </br>
<input type="checkbox" name="brand" value="Brand2"/>Brand2 </br>
<input type="checkbox" name="brand" value="Brand3"/>Brand3 </br>
<input type="checkbox" name="brand" value="Brand1"/>Brand4 </br>
</form>
<form id="teamfilter" action="">
<input type="checkbox" name="team" value="TeamA"/>TeamA </br>
<input type="checkbox" name="team" value="TeamB"/>TeamB </br>
<input type="checkbox" name="team" value="TeamC"/>TeamC </br>
<input type="checkbox" name="team" value="TeamD"/>TeamD </br>
</form>
이 필터는 내가 원하는대로 작동합니다. 콘솔에서 hide를 show로 바꾸고 Brand1을 Brand2로 바꾸면 TeamA 등이 제대로 작동합니다.
$("#CategoryContent li").not(
$("#CategoryContent li:contains(Brand1)")
).hide();
다음 단계뿐만 아니라 작동하는 이중 필터지고 :이 작업을 점점
$("#CategoryContent li").not(
$("#CategoryContent li:contains(Brand1):contains(TeamA)")
).hide();
내 문제는 두 배입니다. 1은 Brand1/Team A를 변수 (따라서 formids)로 대체합니다.
두 번째는 체크 박스를 클릭했을 때 스크립트를 실행하려고합니다. 둘 중 하나를 클릭하고 둘 다 클릭하면 작동합니다 (위의 스크립트를 사용하면 모두 표시 한 다음 숨기기로 재설정해야 함).
현재이 스크립트를 실행 중이지만 문제가 발생하여 필터가 1 개만 돌아갔습니다.
$("input:checkbox[name='brand']").click(function() {
var brandfilter = $(this).val();
alert (brandfilter);
$("#CategoryContent li:contains(' + brandfilter + ')").parent().hide();
});
팝업 경고 내가 (즉 Brand1) 원하지만 숨기기 기능은 이후에 작동하지 않습니다와 나는 다시 콘솔에 다시 내가 [object HTMLFormElement]
을 얻을 alert (brandfilter)
때 것입니다. 그래서 변수가 올바르게 저장되지 않았다고 생각합니까?
다음은 간단한 작업 기본 스크립트 http://jsfiddle.net/7gYJc/
체크 된 값이 포함 된 모든 항목을 표시하는 것이 좋습니다. 예 : TeamA와 TeamB 상자를 모두 확인하면 어떻게됩니까? – verdesmarald
또한 Brand4의 값이 잘못되었습니다. :) – verdesmarald