更新时间: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);
}
});
请参见 工作小提琴