我想在jQuery中編寫一個小型庫,我想添加一些生命週期事件。我明白我必須在末尾return this;
繼續鏈接。如何創建自定義事件並使用jQuery的.on()調用它們?
樣機我的圖書館至今:
(function($))
$.fn.myLibrary = function(){
// some code here
return this;
}
)(jQuery)
這是我想要什麼,最終的結果是:
$('#selector').myLibrary({
// some options
})
.on('myLibrary-deleting', function(){
// some code
});
我不知道,如果這個問題是正確的,但措辭我如何擴展jQuery的功能?
這可能幫助:http://stackoverflow.com/questions/399867/custom-events-in-jquery – Rajesh