在EventListener中获取Event

时间:2012-03-06 09:32:55

标签: javascript javascript-events

以下代码无效:

slider.prototype.onTransitionEnd = function() {
  var self = this;
  self.slideElement.addEventListener(self.startEvent, function() { self.onTouchStart(/* e, event or what? */ }, false); 
}

slider.prototype.onTouchStart = function(e) {
alert(e);
//HERE I NEED THE EVENT, HOW CAN I GET THIS?
}

问题是,我无法访问函数“onTouchStart”中的事件。 默认情况下,事件会自动转移:

function onTransitionEnd() {
  slide.addEventListener(startEvent, onTouchStart, false);
}
function onTouchStart(e) {
alert(e) /* IT WORK'S! */
}

但是在我的例子中它是如何工作的?

1 个答案:

答案 0 :(得分:0)

你似乎错过了一个括号。这可能是错的吗?

slider.prototype.onTransitionEnd = function() {
  var self = this;
  self.slideElement.addEventListener(self.startEvent, function() { self.onTouchStart(/* e, event or what? */) }, false); 
}

slider.prototype.onTouchStart = function(e) {
    alert(e);
    //HERE I NEED THE EVENT, HOW CAN I GET THIS?
}