【发布时间】:2011-10-16 02:39:53
【问题描述】:
当我单击复选框时,我需要根据复选框是否被选中来触发一些代码。
但由于某种原因,.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/
【问题讨论】:
标签: javascript jquery