我有这段代码:
$('.errorbox').click(function(event){
console.log(event.hasClass('disabled'));
});
有人知道为什么事件没有返回我点击的项目的类吗?
答案 0 :(得分:2)
this
引用处理程序注册到的dom元素,以便您可以检查
$('.errorbox').click(function(event){
console.log($(this).hasClass('disabled'));
});
答案 1 :(得分:1)
$('.errorbox').click(function(event){
console.log(event.currentTarget.hasClass('disabled'));
});
答案 2 :(得分:0)
$('.errorbox').click(function(event){
console.log($(event.target||event.srcElement).hasClass('disabled'));
});