当我使用下面的代码时,我无法获取 jQuery this
来隐藏元素。
$('.purplePanda').click(function(e){
this.hide();
});
我收到这个错误:
未捕获的类型错误:this.hide 不是一个函数
最佳答案
替换
this.hide();
与
$(this).hide();
因此你的函数应该是这样的
$('.purplePanda').click(function(e){
$(this).hide();
});
查看官方文档here
关于jQuery 方法不适用于事件处理程序中的 'this',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30016328/