前端页面html
<tr v-for="(log,index) in logList">
<td><input name="ids" :value="log.logId" type="checkbox"></td>
</tr>
js代码 - 循环获取checkbox复选框的值
var checkedValueList = [];
$("input:checkbox:checked").each(function(){
checkedValueList.push($(this).val());
});
console.log("checkedValueList = " + checkedValueList);
checkbox全选、全不选、反选功能
checkAll:function() {
$("input[name='ids']").prop("checked",true);
console.log("选中个数 size = "+ $("input:checkbox:checked").length)
},
checkNoAll:function() {
$("input[name='ids']").prop("checked",false);
console.log("选中个数 size = "+ $("input:checkbox:checked").length)
},
reverseCheck:function() {
$("input[name='ids']").each(function(){
if($(this).prop("checked")) {
$(this).prop("checked", false);
}else{
$(this).prop("checked", true);
}
});
},
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
jQuery 1.6及以后版本中,建议使用
prop()
函数来设置或获取
checked、selected、disabled
等属性,其它能够用prop()实现的操作,也尽量使用prop()函数