我正在制作一个带有关闭按钮的简单通知,该按钮应使其淡出:
this.close.on("click",this.clear);
}
Notification.prototype.clear = function(){
this.node.fadeOut();
};
但是,当我单击它时,它会抛出此异常“Uncaught TypeError:无法调用未定义的方法'fadeOut'”
我尝试传递一个调用clear方法的函数表达式,它起作用了。
所以我的问题是为什么第一次不起作用但第二次却起作用了。
最佳答案
您需要按如下方式使用 jquery 对象:
$(this.node).fadeOut();
提供的节点代表一个 DOM 对象,这将使用 jquery 淡出该对象。
关于javascript - jQuery : Passing a method directly to the on event handler isn't working,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20750026/