去评论
推扬网

杨晨光:jquery的checkbox选中不选中触发事件

admin
2020/08/12 17:11:14

简延芮的回答:

<!--默认选中--><input type="checkbox" checked="checked" id="ck">                &lt;script&gt;                    $(function () {            // 动态绑定默认状态            //  $("#ck").attr("checked",true)//选中            // $("#ck").attr("checked",false)//未选中            //点击判断选中还是未选中                        $("#ck").click(function () {                            if ($(this).is(":checked")) {                                alert("选中");                            } else {                                alert("未选中");                            }                        })                    });                &lt;&#47;script&gt;

春风秋雨的回答:

<!--默认选中--><input type="checkbox" checked="checked" id="ck">                &lt;script&gt;                    $(function () {            // 动态绑定默认状态            //  $("#ck").attr("checked",true)//选中            // $("#ck").attr("checked",false)//未选中            //点击判断选中还是未选中                        $("#ck").click(function () {                            if ($(this).is(":checked")) {                                alert("选中");                            } else {                                alert("未选中");                            }                        })                    });                &lt;&#47;script&gt;