layui动态设置checkbox选中状态

今天在使用jquery动态设置layui的checkbox元素的选中状态时始终只能取消选中,却不能重新勾选,点击勾选则没有问题,代码如下

if (value == "true") {
    $("#select1").attr("checked", "checked");
} else {
    $("#select1").removeAttr("checked");
}

百度很久终于找到一个可用的解决方案,使用prop代替attr,如下:

if (value == "true") {
    //$id.attr("checked", "checked");
    $id.prop("checked", true);
} else {
    $id.prop("checked", false);
    //$id.removeAttr("checked");
}

博客迁移到github了,这边基本不更新,
主要是没有找到快捷的同步方法,手动同步太麻烦了,如果你有快速把github博客同步到博客园的方法请一定告诉我
别忘了告诉我!!!
别忘了告诉我!!!
别忘了告诉我!!!

原文地址:https://www.cnblogs.com/missile/p/10062723.html