<input type="checkbox" name="topic_id[]" value="1">橘子
<input type="checkbox" name="topic_id[]" value="1">苹果
<input type="checkbox" name="topic_id[]" value="1">梨
<input type="checkbox" name="topic_id[]" value="1">橙子
<input type="checkbox" id="all" name="selectall" value="1">全选
$("#all").click(function(){
if(this.checked){
$('input[name="topic_id[]"]').prop("checked", true);
}else{
$('input[name="topic_id[]"]').prop("checked", false);
}
});
我最初用的是 attr(),只能单词勾选,改成prop()就可以了
原文链接:http://www.codelovers.cn/article/20180606150614.html