我有以下代码:
<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>
我想要做的是在默认情况下隐藏第二个字段集,如果一个人选择了Yes,那么这个框就会出现,如果他们选择了No或者没有选中Yes,那么这个框就会再次隐藏起来。
有人能帮上忙吗?谢谢。
发布于 2011-10-23 18:12:17
Ref Nick Craver -很好的解决方案,尽管它更容易实现,如下所示
$("input[name='solidworks']").change(function() {
$("#boxReseller").toggle();
});
$("input[name='solidworks']:checked").change(); //trigger correct state onload
通过将切换保留为通配符(未定义,无论您喜欢哪个术语),我发现它的工作效率更高。不过很好,谢谢:)
发布于 2010-09-25 05:27:50
你可以这样做:
$("input[name='solidworks']").change(function() {
$("#boxReseller").toggle(this.value == "Yes");
});
$("input[name='solidworks']:checked").change(); //trigger correct state onload
You can give it a try with the markup in the question here,并尝试pre-checked "Yes" version here。
发布于 2010-09-25 05:28:57
演示
http://jsfiddle.net/Wpt3Y/
jQuery(function(){
jQuery("input[name=solidworks]").change(function(){
if ($(this).val() == "Yes") {
jQuery("#boxReseller").slideDown()
}
else {
jQuery("#boxReseller").slideUp();
}
});
});
https://stackoverflow.com/questions/3791038
复制相似问题