简体   繁体   中英

How do I uncheck a checkbox?

I have a checkbox that is always checked, but base on user input elsewhere in my form (I have a onChange="functionName" on a select box) I would like to uncheck it.

How do I do that?

does it need to be done with jQuery ? what about JavaScript please try this:

Check: document.getElementById("ckBox").checked = true;

UnCheck: document.getElementById("ckBox").checked = false;

$('#mycheckbox').attr('checked', false)

plese see this post

also note that in jquery 1.6 you should use

$(".mycheckbox").prop("checked", true/false)

Check it:

$('input[name=foo]').attr('checked', true);

Uncheck it:

$('input[name=foo]').attr('checked', false);

Adjust selector accordingly.

You just needs to remove the attribute checked from the element.

$("#yourSelect").change(function () {
    $("#yourCheckBox").removeAttr("checked");
});

I suppose the easiest method is to call $('theCheckbox').click()

You could also use $('theCheckbox').checked = false , or $('theCheckbox').removeAttribute('checked')

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