【发布时间】:2012-01-17 20:13:24
【问题描述】:
原代码:
this.control.addEventListener('click', $.proxy(function() {
this.time.hashours = (this.duration() / 3600) >= 1.0;
this.time.duration.text(getTime(this.duration(), this.controls.time.hasHours));
this.time.current.text(getTime(0, this.controls.time.hasHours));
}, this));
跨浏览器支持的尝试:
$(this.control).bind('click', $.proxy(function(e) {
var o = e.delegateTarget;
o.time.hashours = (o.duration() / 3600) >= 1.0;
o.time.duration.text(getTime(o.duration(), o.controls.time.hasHours));
o.time.current.text(getTime(0, o.controls.time.hasHours));
}, this));
即使使用代理,this 的上下文也不再属于调用对象,因为 jQuery 的自定义事件模型。如何获取原始this.control?
【问题讨论】:
标签: jquery this bind addeventlistener