2014-06-12 65 views
1

我遇到了一個奇怪的問題與codeschools jquery課程,我的點擊處理程序不工作。我們試圖在5.10要解決的問題是:codeschool jQuery返回航班5.10上點擊處理程序失敗

對於初學者使用創建一個事件處理程序,爲目標的 。看,照片的每個.tour內鏈接。單擊此按鈕時,運行 函數,該函數將向巡視添加一個is-showing-photofy類。 您可能希望在事件 處理程序之外保存對此的引用,並在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 

任何人都可以點我在正確的方向?

回答

2

我錯過以下內容:

  • 防止默認
  • VAR遊= $(這)

終極密碼:

$.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(); 
}); 
相關問題