这是我的设置:如果radiobutton1
在页面加载时已经选中(它checked="checked"
在查看源代码中)并且我在选择后尝试取消选中它,则在选择后radiobutton2
属性checked
onradiobutton1
不会被删除radiobutton2
:
if($('#' + radiobutton1_ID).is(':checked'))
UncheckRadioButton('#' + radiobutton2_ID);
// Utility function to clear a radiobutton's "checked" attribute
function UncheckRadioButton(radiobuttonID) {
radiobuttonID.removeAttr("checked");
}
选择radiobutton2
并执行“查看源代码”后,我看不到任何checked="checked"
内容radiobutton2
(即使页面显示此按钮已选中),并且radiobutton1
它仍然显示checked="checked"
。这是为什么?应该反过来。
更新
这是我的更多代码。我知道if
语句部分受到打击,所以这不是问题,而且我知道我使用的单选按钮 ID(ccRadioBtn
和checkRadioBtn
)paypalRadioButton
是正确的:
var ccRadioBtn = ccRadioButton; // credit card radio button ID
var paypalRadioButton = payPalRadioClientID;
// ...
if (paypalIsSelected()) {
UncheckRadioButton(checkRadioBtn);
UncheckRadioButton(ccRadioBtn);
// ...
} else {
// force a clear on any previously selected payment options
CheckRadioButton(ccRadioBtn); // default to credit card radio button
UncheckRadioButton(paypalRadioButton);
UncheckRadioButton(checkRadioBtn);
// ...
}
}
function UncheckRadioButton(radiobuttonID) {
$('#' + radiobuttonID).removeAttr("checked");
}
function CheckRadioButton(radiobuttonID) {
$('#' + radiobuttonID).attr('checked', true);
}
问题是:如果一个单选按钮默认为checked="checked"
并且我单击另一个单选按钮,checked
则应删除第一个单选按钮的属性,但事实并非如此。并且已选择的第二个单选按钮没有checked="checked"
应有的值。当我查看页面源时,我可以看到这一点。我不确定为什么这不起作用。