复选框不能正常工作与jquery的IE [英] Checkbox not working properly for IE with jquery
问题描述
我尝试在页面上使用多个asp.net复选框,因此禁用它们。
I am trying using several asp.net checkboxes on a page, disabling them accordingly.
<asp:CheckBox ID='chkMenuItem' runat='server' CssClass='HiddenText' Text='Test' onclick='<%#String.Format("checkChild({0});", Eval("id")) %>' />
在javascript上,我使用以下代码
on javascript, I am using the following code
function checkChild(id) {
for (i = 0; i < $("input[id*=hdnParentMenuItemID]").length; i++) {
if ($('input[id*=hdnParentMenuItemID]')[i].value.split(':')[0] == id) {
var childID = $('input[id*=hdnParentMenuItemID]')[i].value.split(':')[1];
if ($("#" + childID).attr("disabled"))
//$("#" + childID).attr('disabled', '');
$("#" + childID).removeAttr("disabled");
else
$("#" + childID).attr('disabled', true);
}
}
}
一旦页面加载,removeAttr部分不工作。我试图通过调试器和逻辑工作完全正常。如果在网页加载时没有禁用复选框,代码可以正常工作。我试图替换禁用的属性与检查,看看其他属性是否工作正常,它的工作完全正常。我尝试了
Now is the checkboxes are disabled once the page is loaded, the removeAttr section doesn't work. I tried to step through the debugger and the logic works perfectly fine. If the checkboxes aren't disabled on page load, the code works fine. I tried replacing disabled 'attributes' with 'checked' to see if the other attributes work fine and it works perfectly fine. I tried
$("#" + childID).attr('disabled', '');
但它无效。
感谢,
推荐答案
我有类似的问题使得在Internet Explorer中使用jQuery < asp:CheckBox />
下面的代码在FireFox中运行得很好。
I had similar problems enabling an <asp:CheckBox />
in Internet Explorer using jQuery. The following code worked perfectly fine in FireFox.
$('myCheckBox').removeAttr('disabled');
但是,在IE中无法正常工作。
However, it failed to work properly in IE.
< asp:CheckBox />
会以< span />
< input />
和< label />
标记。当禁用复选框时,span和输入标记都将使用disabled属性进行装饰。为了获得预期的行为,我习惯了下面的代码:
An <asp:CheckBox />
is rendered as a <span />
with an <input />
and a <label />
tag. When the checkbox is disabled both the span and the input tags are decorated with the disabled attribute. To get the expected behavior I used to the following code:
$('myCheckBox').removeAttr('disabled');
$('myCheckBox').closest('span').removeAttr('disabled');
这篇关于复选框不能正常工作与jquery的IE的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!