ai didi

javascript - 如果将两个单选按钮设置为 "Yes",我如何组合它们以显示相同的元素?

转载 作者:行者123 更新时间:2023-11-30 10:36:38 24 4
gpt4 key购买 nike

这是我在 jQuery 中所拥有的:

$(document).ready(function(){
$("input[name='DifficultyObtainingCMELicenseRenewal']").change(function() {
$("#DifficultyObtainingCME").toggle(this.value == "Yes");
});
$("input[name='DifficultyObtainingCMEBoardCertification']").change(function() {
$("#DifficultyObtainingCME").toggle(this.value == "Yes");
});
});

这是 HTML:

 <tr>
<th><label>Do you have difficulty obtaining enough CME required for Iowa license renewal?</label></th>
<td>
<label><input type="radio" name="DifficultyObtainingCMELicenseRenewal" value="Yes" class="checkbox"/> Yes</label><br />
<label><input type="radio" name="DifficultyObtainingCMELicenseRenewal" value="No" class="checkbox"/> No</label>
</td>
</tr>
<tr>
<th><label>Do you have difficulty obtaining enough CME required for your specialty board certification/re-certification?</label></th>
<td>
<label><input type="radio" name="DifficultyObtainingCMEBoardCertification" value="Yes" class="checkbox"/> Yes</label><br />
<label><input type="radio" name="DifficultyObtainingCMEBoardCertification" value="No" class="checkbox"/> No</label>
</td>
</tr>
<tr id="DifficultyObtainingCME" style="display:none">
<th class="altTH"><label>Please elaborate on the difficulties you are experiencing:</label></th>
<td class="altTD">
<cftextarea name="DifficultyObtainingCMEOther" rows="3" cols="20"></cftextarea>
</td>
</tr>

所以现在,如果您在其中一个框上按"is",它会显示额外的字段,但在另一个框上按“否”会使它消失,反之亦然。我如何做到这一点,只要其中一个设置为"is",它就会保持打开状态?

这是一个链接:http://jsfiddle.net/madcaesar/hcZXf/

最佳答案

只需确保在更改发生时选中"is"选项:

var thingToToggle = $("#DifficultyObtainingCME");
var allRadios = $('input[type="radio"]');

allRadios.change(function () {
if (allRadios.filter(function () {
return this.checked && this.value === 'Yes';
}).length > 0) {
thingToToggle.show();
} else {
thingToToggle.hide();
}
});

http://jsfiddle.net/JptF8/

关于javascript - 如果将两个单选按钮设置为 "Yes",我如何组合它们以显示相同的元素?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13650978/

24 4 0
文章推荐: javascript - 使用 .each() 两次
文章推荐: swift - 在swift中的代码中修改其高度约束后,UILabel不显示全文
文章推荐: java - 拓扑排序与DFS的区别仅在于当前元素的处理是在递归调用之后完成的
文章推荐: swift - AvFoundation框架,AvPlayer暂停方法导致应用程序最小化后崩溃
行者123
个人简介

我是一名优秀的程序员,十分优秀!

滴滴打车优惠券免费领取
滴滴打车优惠券
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com