且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

div中的复选框在单击时使用jquery 1.9.1选中或未选中

更新时间:2023-11-30 19:23:04

在jQuery 1.9.x上不建议使用.live(),不建议使用checked html属性切换复选框,请使用.prop('checked')相反,您更新的代码应为:

The use of .live() is deprecated on jQuery 1.9.x , also the use of checked html attribute to toggle checkboxes is deprecated, use .prop('checked') instead, your updated code should be:

$("div.tel_show").on("click",function(event) {
    var target = $(event.target);
    if (target.is('input:checkbox')) return;

    var checkbox = $(this).find("input[type='checkbox']");

    if( !checkbox.prop("checked") ){
        checkbox.prop("checked",true);
    } else {
        checkbox.prop("checked",false);
    }
});

请参见 工作小提琴