$(".answer").on("click", function () {
console.log(this) //dom对象
console.log(this.attr("class")) //报错 this.attr is not a function
});
jq调用方法要使用jq对象.方法名(xxx)
$(".answer").on("click", function () {
console.log($(this)) //jq对象
console.log($(this).attr("class"))
});
如果回调函数是下面这个形式的
()=>{
....
}
则要写成
$(".answer").on("click", (el)=>{//el事件对象
console.log($(el.target))
console.log($(el.target).attr("class"))
});
注:dom对象obj转换为jq对象 ------> $(obj)