我试图获取一个复选框来检查并取消选中它是否未被选中。它正在检查是否未选中 - 但如果选中,则不会取消选中。很奇怪。提前致谢!使用Jquery检查和取消选中复选框
这里是我的代码:
编辑:这里的的jsfiddle:http://jsfiddle.net/itamark/UnR4X/
JS:
$(':checkbox').mouseenter(function(){
if($(this).not(':checked')) {
alert('notchecked');
$(this).attr('checked', true);
}
else if($(this).is(':checked')){
alert('ischecked');
$(this).attr('checked', false);
}
})
HTML:
<input type="checkbox" name"myCheck" id="chk1"/>Checkbox</label>
试试这个 - http://stackoverflow.com/questions/426258/how-do-i-check-a-checkbox-with- jquery-or-javascript –
在悬停时执行此操作有点毫无意义,因为只要您取消悬停/鼠标悬停,复选框将始终*取消选中,无论用户的行为如何。这是什么意思? –
@DavidThomas是的 - 我已经切换到'.mouseenter'。我会更新代码。 – itamar