我有一些粗略的代码,可以让我根据两个单选按钮过滤一些结果。我正在努力添加第三个变体,它将作为“全部显示”,即一次显示所有四个 div。任何帮助将非常感激。
<p class="text1">Variants
<label>
<input type="radio" name="type" value="variant-2" id="type_0" checked="checked" />
Variant 1</label>
<label>
<input type="radio" name="type" value="variant-1" id="type_1" />
Variant 2</label>
</p>
<script>
$(document).ready(function(){
$("input[name$='type']").click(function(){
var value = $(this).val();
if(value=='variant-2') {
$(".variant-1").show();
$(".variant-2").hide();
}
else if(value=='variant-1') {
$(".variant-2").show();
$(".variant-1").hide();
}
});
$(".variant-1").show();
$(".variant-2").hide();
});
</script>
<div class="variant-1">Variant 1</div>
<div class="variant-2">Variant 2</div>
<div class="variant-1">Variant 1.1</div>
<div class="variant-2">Variant 2.1</div>