jQuery判断input checkbox是否选中和给checkbox赋值

判断checkbox是否选中

判断选中方法一

$("#checkbox-id").get(0).checked
$("#checkbox-id")[0].checked

判断选中方法二

$('#checkbox-id').is(':checked')

判断选中方法三

$('#checkbox-id').prop('checked')

jquery给checkbox赋值

所有的jquery版本赋值方法

//所有的jquery版本都可以这样赋值:
$("#cb1").attr("checked", "checked");
$("#cb1").attr("checked", true);

jquery1.6+的赋值方法

//jquery1.6 +:
//prop的4种赋值:
$("#cb1").prop("checked", true);//很简单就不说了哦
$("#cb1").prop({checked: true}); //map键值对
$("#cb1").prop("checked", function () {
    return true;//函数返回true或false
});
$("#cb1").prop("checked", "checked");

参考:

https://www.cnblogs.com/cssfirefly/p/4571679.html

https://blog.csdn.net/limingchuan123456789/article/details/11499665

发表回复

您的电子邮箱地址不会被公开。 必填项已用*标注




Enter Captcha Here :