选择click-checkbox里面的任何内容都切换checkbox状态。
html:
<div>
<div class="click-checkbox">
<input type="checkbox" id="box">
<span>记住密码</span>
</div>
</div>
jquery:
$(document).on('click', '.click-checkbox', function () {
$(this).find('#box:checkbox').click();
})
$(document).on('click', '#box:checkbox', function (e) {
e.stopPropagation();
});
扩展:判断check是否选中和默认选中checkbox
//判断是否选中
f($("#box").is(':checked')){
console.log("选中")
}else{
console.log("未选中")
}
//选中checkbox
$('#box').prop("checked",true);