jq判断checked复选框
本文介绍了jQuery对checkBox复选框操作:设置和取消选中操作,判断是否选中,希望对您有用。
一、jquery对checkBox复选框操作:选中、取消
$("#ck").attr("checked", "checked"); //设置选中
$("#ck").removeAttr("checked"); //设置不选中
$("#ck").prop("checked", true); // true设为选中 false设为取消
二、jquery对获取checkBox状态:判断checkBox是否被选中:
方法1:
if ($("#checkBox-id").get(0).checked) {
//.get(0)方法,返回的是原生标签对象
}
方法2:
if($('#checkBox-id').is(':checked')) {
//input标签上,不存在checked属性的也有效
//推荐使用
}
方法3:
if ($('#checkBox-id').attr('checked')) {
//注:input标签上,存在checked属性的才有效
//input标签上不存在checked属性时候,总是返回undefined,无法判断
}
2022-12-22 有友博客