我需要根据复选框是否被选中来在单击复选框时触发一些代码。
但出于某种原因,.is(':checked')
总是被触发。
这是我的代码。
jQuery('#selectlist input[type=checkbox]').live('click',function(){
var select_id = jQuery(this).attr('id');
if(jQuery(this).is(':checked')) {
alert('You have unchecked the checkbox');
// Remove some data from variable
} else {
alert('You have checked the checkbox');
//Add data to variable
}
}
更新
我在 JSFiddle 上添加了一个示例:http://jsfiddle.net/HgQUS/
最佳答案
使用change
代替click
关于javascript - 如何检查单击时是否选中了复选框?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6876154/