Select all checkboxes issue(jQuery)
I have a little issue, if i select an single checkbox and press f5 the state of the checbox will remain(so it will be checked) but if i use jQuery to select all checkboxes on a page and then press f5 a开发者_开发知识库ll of the checkboxes will blank(so uncheck, only the one's that are handpicked will remain in there state). How can i solve this, so that when i hit refresh everything will remain the same?
the code
jQuery('.sellectall').click(function(){
$('input:checkbox').attr('checked',true);
});
I assume you're using jQuery 1.6 or later.
If so, use the prop()
[docs] method instead of the attr()
[docs] method.
Then you should get the same behavior as if a user clicked the box.
jQuery('.sellectall').click(function(){
$('input:checkbox').prop('checked',true);
});
...or set the checked
property manually:
jQuery('.sellectall').click(function(){
$('input:checkbox').each(function() { this.checked = true; });
});
精彩评论