显示框,如果单选按钮使用jQuery检查
问题描述:
我有以下的code:
<fieldset>
<legend>Do you currently have SolidWorks</legend>
<ul>
<li><label for=""><input type="radio" name="solidworks" value="Yes" id="rdYes" /> Yes</label></li>
<li><label for=""><input type="radio" name="solidworks" value="No" id="rdNo" /> No</label></li>
</ul>
</fieldset>
<fieldset id="boxReseller" style="display:none;">
<legend>Who is your SolidWorks reseller?</legend>
<ul>
<li><label for=""><input type="radio" name="reseller" value="Cad Connect" /> Cad Connect</label></li>
<li><label for=""><input type="radio" name="reseller" value="Cadtek" /> Cadtek</label></li>
<li><label for=""><input type="radio" name="reseller" value="CCSL" /> CCSL</label></li>
<li><label for=""><input type="radio" name="reseller" value="Innova" /> Innova</label></li>
<li><label for=""><input type="radio" name="reseller" value="NT CAD/CAM" /> NT CAD/CAM</label></li>
<li><label for=""><input type="radio" name="reseller" value="Solid Engineer" /> Solid Engineer</label></li>
<li><label for=""><input type="radio" name="reseller" value="Solid Solutions Ireland" /> Solid Solutions Ireland</label></li>
<li><label for=""><input type="radio" name="reseller" value="Solid Solutions Management" /> Solid Solutions Management</label></li>
<li><label for=""><input type="radio" name="reseller" value="TMS Scotland" /> TMS Scotland</label></li>
</ul>
</fieldset>
我想要做的是默认隐藏第二字段集,如果一个人选择是,然后将出现的框,如果他们选择否或不选择是那么框将再次隐藏。
What I want to do is hide the second fieldset by default and if a person chooses Yes then the box will appear, and if they choose No or Yes is not selected then the box will hide again.
谁能帮助?谢谢你。
答
参考尼克Craver - 很好的解决方案,虽然它是如下
Ref Nick Craver - Nice solution although it is more felxaible as below
$("input[name='solidworks']").change(function() {
$("#boxReseller").toggle();
});
$("input[name='solidworks']:checked").change(); //trigger correct state onload
通过让拨动作为通配符(未定义任何术语你preFER),我发现它的工作效率更高。尼斯虽然,谢谢:)
By leaving the toggle as a wild card (undefined whichever terminology you prefer) I found it worked more efficiently. Nice though, thanks :)