Jquery .click() 更胜一筹
在我的类的方法中,我有:
this.background.click(function() {
this.terminate();
});
显然 this.terminate();
不起作用,因为 this
引用 this.background
内部 <代码>jquery.click函数。我该如何编写才能从上级获取 this
?
Inside a method of my class I have:
this.background.click(function() {
this.terminate();
});
Obviously this.terminate();
doesn't work because this
refers to this.background
inside jquery.click
function. How do I have to write for get this
from superior class?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
声明一个包含外部
this
的变量:Declare a variable containing the outer
this
:尝试:
Try:
你可以像@Andrew所说的那样,或者可以制作“yourObject.terminate();”
例如:
为了改进,请确保“background”选择器存在(如果 javascript 在 html 之前加载),并使用 jquery“live()”或“delegate()”或“on()”在元素中附加事件。
you can make like @Andrew said, or can make "yourObject.terminate();"
Ex:
for improve, ensure the 'background' selector exists (if javascript load before html), and use jquery "live()" or "delegate()" or "on()" to attach events in the elements.
使用绑定
Use bind