我有車的名單,像這樣的:(簡化當然)如何爲jQuery中的項目列表創建過濾器?
<div class="car" data-image="true" data-specs="true">
1. BMW
</div>
<div class="car" data-image="false" data-specs="true">
2. Mercedes
</div>
<div class="car" data-image="true" data-specs="false">
3. Audi
</div>
<div class="car" data-image="false" data-specs="false">
4. Jaguar
</div>
我要的是複選框,將過濾汽車的列表。
With image <input name="with_image" type="checkbox" />
With specs <input name="with_specs" type="checkbox" />
如果兩個複選框都打勾,我想只顯示第一輛車,其他車輛隱藏。
問題是,如果我只是hide()
和show()
他們當複選框被選中或取消選中,它不會知道其他複選框是否被選中。例如,如果我選擇了兩個複選框,則只顯示第一輛汽車,但是如果我取消選中第一輛汽車,即使沒有圖像,也會顯示第四輛汽車。
我該如何克服這一點?