无法使用JavaScript启用复选框

时间:2014-08-26 12:36:26

标签: javascript asp.net ajax

我有一个ASP.NET网站。在后面的代码中创建一个复选框,禁用如下:

cBox = New CheckBox
cBox.ID = "Link" & lngUSN & "|" & objTableMapping.DatasetName & "|" & CStr(objDRInput("URNs")) & "|" & intLinkCount & "|" & objTableMapping.Reference
cBox.InputAttributes.Add("class", "Link" & lngUSN & "|" & objTableMapping.DatasetName & "|" & CStr(objDRInput("URNs"))) '& "|" & intLinkCount)
cBox.Checked = False
cBox.Enabled = False

页面加载(通过AJAX加载)后,应按如下方式启用复选框:

window.onload = EnableLinkAndUnLinkCheckboxes;

function EnableLinkAndUnLinkCheckboxes()
    {
        //Go through all of the checkboxes on the webpage and ensure they are enabled
        var frm = document.forms[0];
        for (i = 0; i < frm.elements.length; i++) {
            if (frm.elements[i].type == "checkbox") {
                alert('got here')
                frm.elements[i].disabled = false;
                }
            }
    }

“Got here”警告多次显示,表示已达到以下代码:frm.elements[i].disabled = false;,但未启用复选框。这是为什么?

1 个答案:

答案 0 :(得分:-1)

尝试下面一个。

function EnableLinkAndUnLinkCheckboxes() {
        //Go through all of the checkboxes on the webpage and ensure they are enabled
        var frm = document.forms[0];
        for (i = 0; i < frm.elements.length; i++) {
            if (frm.elements[i].type == "checkbox") {
                frm.elements[i].removeAttribute('disabled');
                frm.elements[i].parentElement.removeAttribute('disabled');
            }
        }
    }