<pre name="code" class="javascript"><pre name="code" class="html">JS代码:
$(function(){
$('#select').on('click',function(){
if($(this).prop('checked')){
$("input[name=items]").each(function(){
$(this).prop('checked',true);
});
}else{
$("input[name=items]").each(function(){
$(this).prop('checked',false);
});
}
});
})
.attr()方法能获得属性的名称,即 checked width height等
.prop()获得属性对应的值,即checked是true或者false
<input type="checkbox" id="select" />
<input type="checkbox" name="items" />
<input type="checkbox" name="items" />
<input type="checkbox" name="items" />
<input type="checkbox" name="items" />