原始代码:jQuery的:从的addEventListener切换到绑定
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));
即使有代理,这样的背景下已经不再属于由于jQuery的自定义事件模型而调用对象。我怎样才能得到原来的this.control
?
你说得对。使用'.on'代替'.bind'可以使用'$ .proxy',谢谢! – 2012-01-17 20:34:00
@BrianGraham - 'bind'和'on'在这个特定的例子中没有任何功能上的区别。这可能是导致错误的其他原因。 – Anurag 2012-01-18 01:42:27