开发者

How do I uncheck a checkbox?

开发者 https://www.devze.com 2023-03-05 04:27 出处:网络
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.

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')

0

精彩评论

暂无评论...
验证码 换一张
取 消