Checkbox not working properly for IE with jquery

I am trying to use several asp.net flags on a page, disabling them accordingly.

<asp:CheckBox ID='chkMenuItem' runat='server' CssClass='HiddenText' Text='Test'      onclick='<%#String.Format("checkChild({0});", Eval("id")) %>' />

in javascript, I use 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);
                }
            }
        }

Now the checkboxes are disabled after the page loads, the removeAttr section does not work. I tried going through the debugger and the logic works fine. If the checkboxes are not disabled when the page loads, the code works fine. I tried replacing the disabled attributes with 'checked' to see if other attributes worked, and it worked fine. I tried

 $("#" + childID).attr('disabled', '');

but he didnโ€™t work either.

Note. It works fine on FF and Chrome, but doesn't work on IE.

Thanks,

+5
source share
4 answers

, <asp:CheckBox /> Internet Explorer jQuery. FireFox.

$('myCheckBox').removeAttr('disabled');

IE.

An <asp:CheckBox /> <span /> <input /> <label />. , , disabled. , :

$('myCheckBox').removeAttr('disabled');
$('myCheckBox').closest('span').removeAttr('disabled');
+12

.

$('#' + childID)[0].disabled = false;
0

if,

if ($("#" + childID + ":disabled").length) // is childID disabled?
    $("#" + childID).removeAttr("disabled"); // enable it
else
    $("#" + childID).attr('disabled', 'disabled'); // disable it
0

, . -, , . , i var, . jQuery, - , , DOM disabled. , , , , , , .

function checkChild(id) {
    var input, checkBox, parts, inputs = $("input[id*=hdnParentMenuItemID]");
    for (var i = 0, len = inputs.length; i < len; i++) {
        input = inputs[i];
        parts = input.value.split(':');
        if (parts[0] == id) {
            checkBox = document.getElementById( parts[1] );
            checkBox.disabled = !checkBox.disabled;
        }
    }
}
0

All Articles