【发布时间】:2015-07-21 01:45:25
【问题描述】:
我有一个带有两个单选按钮的结帐页面,一个用于“注册帐户”和“访客帐户”结帐方法。
我想要一个复选框,当它被选中时,它会选中 Register Account 单选按钮,当它未被选中时,它会选中 Guest Account 结帐单选按钮.
到目前为止,这是我的代码: http://jsfiddle.net/hQbpZ/160/
HTML:
Remember Me for Future Purposes :<input type="checkbox" id="checkbox1"/> <br/><br/>
Register Account :<input type="radio" id="radio1" name="radio"/><br>
Guest Checkout :<input type="radio" id="radio2" name="radio"/><br>
JS:
jQuery('#checkbox1').click(function(){
jQuery('#radio1').attr('checked', true);
});
jQuery('#checkbox1').click(function(){
jQuery('#radio2').attr('checked', false);
});
我关闭了部分功能,但我不知道如何在取消选中复选框时取消选中单选按钮。
【问题讨论】:
-
目前,我真的没有时间深入研究任何内容,但一种选择是隐藏第三个单选按钮并将其用作默认值。有点 Macgyver 解决方案,但它应该很容易解决问题。
标签: javascript jquery html checkbox radio-button