JQuery 1.6.1 and Checkbox Attr
I am using JQuery 1.6.1 and found that
$("#theChk').attr("checked", "");
OR
$("#theChk").prop("checked", false);
none of this are working . Can some one find reason based on this http://blog.jquery.it/2011/05/10/jquery-1-6-1-rc-1-released/ ?
Do I have to 开发者_高级运维change whole application for this change ??!!
You're having "
on the left side of selector and '
on the right side of selector
and use .attr
$("#theChk").attr("checked", false);
to uncheck it, to check it use
$("#theChk").attr("checked", true);
$("#theChk").removeAttr("checked");
Try changing it to this:
$('#theChk').attr('checked', false);
checked takes a boolean not a string. I'm not sure why your example that uses prop
is not working. From what I can see that looks fine.
If you're setting a value, use .prop and a non-quoted boolean:
$('#theChk').prop('checked', true)
If youre checking if it's checked, leave out the boolean:
if ($('#theChk').prop('checked'))
So it depends on what you're trying to do.
精彩评论