这里后,取消一个单选按钮是我的设置:如果radiobutton1
已经选中加载页面时(它有checked="checked"
在查看源代码),我尝试选择radiobutton2
后取消它,在radiobutton1
的checked
属性选择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"
。这是为什么?它应该是相反的。
UPDATE
下面是一些我的代码。我知道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"
。当我查看页面源时,我可以看到这一点。我不知道为什么这不起作用。
我用我的实际代码更新了我的帖子。问题依然存在。 – PositiveGuy 2010-07-16 02:12:03
这个问题最终不是一个JS问题,但我从这个线程中获得了很多。感谢所有回复的人。 – PositiveGuy 2010-07-16 03:51:22