我正在使用jQuery,我需要在未选中时显示复选框的ID.我怎么能做到这一点?
$('input[type=checkbox]').click(function(){
alert(this.id);
if($(this).is(':unchecked')) {
alert(this.id);
}
});
Run Code Online (Sandbox Code Playgroud)
查看此DEMO以获取一个工作示例.
鉴于您的代码:
$('input[type=checkbox]').click(function(){
alert(this.id);
if($(this).is(':unchecked')) {
alert(this.id);
}
});
Run Code Online (Sandbox Code Playgroud)
您需要更改:unchecked为:not(:checked).jQuery从未有:unchecked过滤器.除此之外,你相当接近.
$("input[type=checkbox]").on("click", function(){
if($(this).is(":not(:checked)"))
alert(this.id);
});
Run Code Online (Sandbox Code Playgroud)