问题
在用户控件(.ascx)中,我有一个单选按钮列表,其中有两个单选按钮,其值分别为“开”和“关”,当我单击该按钮时,我希望它为其他一些单选按钮设置选定的单选按钮。也具有相同的“开”和“关”。
当控制单选按钮列表设置为“开”时,我想检查那些相关单选按钮中的“关”单选。并将其设置为“关”时,将那些相关的选项切换回“开”。
另外,我还有一些复选框也需要响应相同的控制“开” /“关”。当其为“开”时,它们应变为未选中状态;而当其为“关”时,它们应处于选中状态。
我现在有什么
以下是我所拥有的。它在Chrome和Firefox中工作正常,但在IE 11中却无法正常工作
在Page_Load()中,我有:
Me.rblController.Items(0).Attributes.Add("OnClick", "ToggleOtherStuff();")
Me.rblController.Items(1).Attributes.Add("OnClick", "ToggleOtherStuff();")
每个响应控制器rbl的单选按钮列表如下所示,它们具有类“ customerRadioButtonList”:
<asp:RadioButtonList ID="rblCustomer1" CssClass="customerRadioButtonList" runat="server" RepeatDirection="Horizontal">
<asp:ListItem>On</asp:ListItem>
<asp:ListItem>Off</asp:ListItem>
</asp:RadioButtonList>
复选框也很简单,它们具有类“ AlertsCheckBox”:
<asp:CheckBox ID="cbxAlertCheck1" CssClass="AlertsCheckBox" runat="server" />
这是响应于控制器无线电的点击而运行的功能:
function ToggleOtherStuff() {
if ($telerik.$('#<%=rblController.ClientID%> input[type="radio"][value="On"]').first().is(':checked')) {
alert('On Clicked'); // This fires OK in IE too
$telerik.$('.customerRadioButtonList input[type="radio"][value="Off"]').prop('checked', true);
$telerik.$('AlertsCheckBox input').prop('checked', false);
} else {
$telerik.$('.customerRadioButtonList input[type="radio"][value="On"]').each(function () {
if (this.disabled == false) {
this.checked = true;
}
});
$telerik.$('AlertsCheckBox input').each(function () {
if (this.disabled == false) {
this.checked = true;
}
});
}
}
我完全感到困惑,为什么这在IE中不起作用。我以为可能是Telerik Ajax的罪魁祸首,所以我删除了使用该控件的页面.aspx中的AjaxManagerProxy,但这没有任何影响。正如我所看到的,由于某些debug alert(),事件运行良好。我放了
我还验证了我使用的Jquery选择器确实返回了值,并且我什至可以读取'checked'属性值。但是我不能设置'checked'属性。设置它无效,所有单选按钮和复选框均未更改。这是怎么回事?
最佳答案
看来这是Telerik问题:
http://www.telerik.com/forums/setting-checked-property-to-decorated-checkboxes-with-javascript-not-working-on-ie11