您好,我需要更改 onMouseMove 的 mousemove 属性,但我无法访问 myfunc 对象,因为 this 引用了 el 不是父级!!
function myfunc (el) {
this.el = el;
this.mousemove = false;
el.onmousemove = function(){
this.mousemove = true;
};
}
最佳答案
只需存储对 this
的引用,您可以随意命名它。通常使用 that
或 self
:
function myfunc(el) {
var that;
that = this;
this.el = el;
this.mousemove = false;
el.mousemove = function () {
that.mousemove = true;
};
}
关于javascript - 访问 parent 的属性(property),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8071824/