嘿,我正在寻找一个非常简单的 jQuery 代码,它在选择某个单选按钮时显示一个 div,如果该单选按钮基于单选按钮值“取消选择”,则隐藏该 div。
我想出了如何使它与一个过滤器的单选按钮一起工作,但我想为两个过滤器解决它说
- 基于它属于哪个类型
- 基于没有............数量
这是适用于第一个过滤器(类型)的代码:
<script>
var $filters = $("input:radio[name='type']");
var $categoryContent = $('#mainhide .mainresultbox');
var $errorMessage = $('#errorMessage');
$filters.click(function() {
// if any of the radio buttons for brand are checked, you want to show div's containing their value, and you want to hide all the rest.
$categoryContent.hide();
var $selectedFilters = $filters.filter(':checked');
if ($selectedFilters.length > 0) {
$errorMessage.hide();
$selectedFilters.each(function (i, el) {
$categoryContent.filter(':contains(' + el.value + ')').show();
});
} else {
$errorMessage.show();
}
});
</script>
这是单选按钮的 HTML。
<ul>
<li><label for="cdg"><input type="radio" id="cdg" name="type" value="brand1"> brand1</label></li>
<li><label for="cdh"><input type="radio" id="cdh" name="type" value="brand2"> brand1</label></li>
<li><label for="cdi"><input type="radio" id="cdi" name="type" value="brand3"> brand1</label></li>
</ul>
<ul>
<li><label for="cdj"><input type="radio" id="cdj" name="quantity" value="10">10</label></li>
<li><label for="cdk"><input type="radio" id="cdk" name="quantity" value="20">20</label></li>
<li><label for="cdl"><input type="radio" id="cdl" name="quantity" value="30">30</label></li>
</ul>
这是 div 及其内容
<div id="#mainhide">
<div>brand1 in stock - 10</div>
<div>brand1 in stock - 20</div>
<div>brand1 in stock - 30</div>
</div>
<div id="errorMessage">reset all fliters</div>
我怎样才能使两个过滤器都起作用,任何人都可以帮助我....
谢谢你,纳雷什·卡米雷迪