Manipulating Checkboxes
I have a list of checkboxes that the user uses to show and hide objects. Some of the check boxes automatically check other boxes, ie: a "Check All" button.
Un开发者_运维问答fortunately, whenever I click the box manually it will no longer respond to functional checking, ie: $("#myCheckBox").attr("checked",true) no longer works.
This is confusing me, what am I missing? It is like when I click the checkbox jQuery can no longer see it.
Thanks.
The "correct" way to set checkboxes and radio buttons as of jQuery 1.6 is $('#myCheckBox').prop('checked',true)
-- or omit the second argument to get the value instead.
In older versions of jQuery, you'd set it like so: $('#myCheckBox').attr('checked','checked')
Try upgrading to the latest version of jQuery and use $("#myCheckBox").prop("checked", true)
. If this doesn't work, it would help if you posted a complete example which isn't working.
精彩评论