我试图为每一个被点击的复选框发出警报。
这是我的 JS 代码:
$('#acts').find(':checkbox').click(function(){
if($(this) == 'all')
{
alert('Checkbox Clicked');
}
});
和 HTML:
<div id="acts">
<input type="checkbox" id="all">
<input type="checkbox" value="Brussel" name="locality"> <label>Brussel</label>
<input type="checkbox" value="Anderlecht" name="locality"> <label>Anderlecht</label>
<input type="checkbox" value="Oudergem" name="locality"> <label>Oudergem</label>
</div>
我首先尝试了这种方式,但也尝试添加
var theName = $(this);
和
var theName = String($(this));
并在 IF 语句中与“theName”进行比较,但 $(this) 或我分配给它的变量不断返回我 [Object][object],我无法像这样比较。