checkbox怎么判断是否选中

下面这种可以使用

if($("#checkbox1").is(':checked')) {
  alert("1");
} else {
  alert("0");
}

还有的说以下两种

方法一:
if ($("#checkbox-id").get(0).checked) {
    // do something
}

方法二:

if ($('#checkbox-id').attr('checked')) {
    // do something
}

但是没有效果

原文地址:https://www.cnblogs.com/loveflycforever/p/5399430.html