How do I uncheck a checkbox?
I have a checkbox that is always checked, but base on user input elsewhere in my form 开发者_Python百科(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')
精彩评论