判定复选框的选中状态

1获取当前状态(.prop())---可用来判断状态
<input type="checkbox" name="test" id="test1"/> //未被选中
<input type="checkbox" name="test" id="test2"/ checked>  //选中
console.log($("#test1").prop("checked"))  //打印出false
console.log($("#test2").prop("checked"))  //打印出true
用prop取值,选中状态为true,未选中状态都是false,
所以要判断是否选中,可以使用.prop("checked")
 
 

2$("input[type='checkbox']").is(':checked')---可用来判断状态

<input type="checkbox" name="test" id="test1"/> //未被选中
<input type="checkbox" name="test" id="test2"/ checked>  //选中
console.log($("#test1").is(":checked"))  //打印出false
console.log($("#test2").is(":checked"))  //打印出true
用.is(':checked'),选中状态为true,未选中状态都是false,
所以要判断是否选中,可以使用.is(':checked')
原文地址:https://www.cnblogs.com/jijingxingkong/p/10981380.html