gpt4 book ai didi

javascript - codeschool jQuery Return Flight 5.10 on click handler failing

转载 作者:行者123 更新时间:2023-11-30 17:26:18 24 4
gpt4 key购买 nike

我在 codeschools jquery 类(class)中遇到了一个奇怪的问题,我的点击处理程序无法正常工作。我们在 5.10 中试图解决的问题是:

For starters create an event handler using on, that targets the .see-photos link within each .tour. When this is clicked, run a function that will add a class of is-showing-photofy to the tour. You'll probably want to save a reference to this outside of your event handler, and use that in the click event handler.

我当前的代码尝试是:

$.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 = $(这个)

最终代码:

$.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();
});

关于javascript - codeschool jQuery Return Flight 5.10 on click handler failing,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24175243/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com