我試圖獲取一個複選框來檢查並取消選中它是否未被選中。它正在檢查是否未選中 - 但如果選中,則不會取消選中。很奇怪。提前致謝!使用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