<div class="e_checkbox">
<input type="checkbox">
<span>选项一</span>
</div>
$('.e_checkbox span').click(function(){
var eInputCheckbox = $(this).parent().find('input');
if(eInputCheckbox.is(':checked')){
eInputCheckbox.attr("checked", false);
console.log(eInputCheckbox.attr("checked"));
}else{
eInputCheckbox.attr("checked", true);
console.log(eInputCheckbox.attr("checked"));
}
});
attr 改成prop
jQuery 建议:To retrieve and change DOM properties such as the checked, selected, or disabled state of form elements, use the .prop() method.
特意写了一篇文章《jQuery 的 attr 与 prop 的区别》