简体   繁体   中英

Enabling checkbox with Javascript

I'm trying to use a bookmarklet to check and uncheck certain check boxes. However, the method the check boxes are created seems a little unconventional.

<DIV class=criteriaSelectorSection id=EntityContatiner>
    <DIV id=EntityContainer_Checked>
        <DIV><INPUT id="c_Checkbox2" onclick=HandleClick(this); type=checkbox CHECKED value=""><LABEL title="Checkbox2">Checkbox 2</LABEL></DIV>
    </DIV>
    <DIV id=EntityContainer_Unchecked>
        <DIV class=cIControls><INPUT id="u_Checkbox1" onclick=HandleClick(this); type=checkbox CHECKED value=""><LABEL title="Checkbox 1">Checkbox 1</LABEL></DIV>
        <DIV class=cIControls style="DISPLAY: none"><INPUT id="u_Checkbox2" onclick=HandleClick(this); type=checkbox CHECKED value=""><LABEL title="Checkbox 2">Checkbox 2</LABEL></DIV>
    </DIV>
</DIV>

When a check box is clicked, it seems to not change its value (in the DOM) until the search button is clicked. Its style in the unchecked div is set to not display. Similarly, if it is disabled by the user, it "moves" (via ASP.NET/Ajax) to the unchecked div.

I have tried document.getElementById("u_Checkbox1").checked = true; , document.getElementById("u_Checkbox1").enabled = true; , and document.getElementById("u_Checkbox1").Click() . However, none of these seem to register. Thanks for any help.

In order to enable this control, you should use...

document.getElementById("u_Checkbox1").disabled = false;

There is no enabled property, counter-intuitive as this is.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM