I am not expert with jQuery but I have tried to create a little script for my application. I want to check all checkboxes but it isn't working correctly.
一开始我试着用attr
,之后我试着用prop
,但是我做错了什么.
I tried this first:
$("#checkAll").change(function(){
if (! $('input:checkbox').is('checked')) {
$('input:checkbox').attr('checked','checked');
} else {
$('input:checkbox').removeAttr('checked');
}
});
But this didn't work.
下一步:这比上面的代码工作得更好
$("#checkAll").change(function(){
if (! $('input:checkbox').is('checked')) {
$('input:checkbox').prop('checked',true);
} else {
$('input:checkbox').prop('checked', false);
}
});
这两个例子都不管用.
JSFiddle:http://jsfiddle.net/hhZfu/4/