jQuery返回航班5.10在点击处理失败

codeschool jQuery Return Flight 5.10 on click handler failing

本文关键字:处理 失败 返回 jQuery      更新时间:2023-09-26

我遇到了一个奇怪的问题与codeschools jquery课程,我的点击处理程序不工作。我们试图在5.10中解决的问题是:

对于初学者,使用on创建一个事件处理程序,它的目标是.see-photos链接在每个。tour中。单击此选项后,运行函数,将一个is- showingphotofy类添加到游览中。您可能希望在事件之外保存对它的引用,并在click事件处理程序中使用它。

我当前的代码尝试是:

$.fn.photofy = function() {
  this.each(function() {
        var tour = $(this)
    tour.on('click.see-photos', 'button', function() {
        $(this).addClass('is-showing-photofy');
    });
  });
}
$(document).ready(function() {
  $('.tour').photofy();
});

,我得到的错误信息是:

Your `on` `click` handler should watch for clicks on the `.see-photos` element within the current tour
谁能给我指个正确的方向?

我错过了以下内容:

  • 阻止违约的
  • var tour = $(This)
最终代码:

$.fn.photofy = function() {
  this.each(function() {
        var tour = $(this);
    tour.on('click.photofy', '.see-photos', function(event) {
      event.preventDefault();
        tour.addClass('is-showing-photofy');
    });
  });
}
$(document).ready(function() {
  $('.tour').photofy();
});