どうしたのですか?これは、jqueryドキュメントで提案されているようにメソッドを分割する前に機能しました。 通話:$(this).Slick('show');
この単純なjqueryプラグインの例で何が問題になっていますか?
(function ($) {
var methods = {
// object literals for methods
init: function (options) {
// initialize settings
var settings = $.extend({
'location': 'center',
'speed': 'normal'
}, options);
},
show: function() {
return this.each(function() {
// plugin code here
alert('success!');
});
},
hide: function() {
// hide
}
};
$.fn.Slick = function (method) {
// method calling logic -- jquery recommended/standard
if (methods[method]) {
return methods[method].apply(this, Array.prototype.slice.call(arguments 1));
} else if (typeof(method === 'object' || !method) {
return methods.init.apply(this, arguments);
} else {
$.error('Method ' + method + ' does not exist on jQuery.Slick');
}
};
})(jQuery);
両方を通じて、典型的なjQueryのやり方で動作するjQueryプラグインの設定を開始するために必要なすべてを提供しますそれが働いた状態に。もう一度同じ手順をもう一度小さなステップで行ごとに繰り返します。各小反復の後、すべてが期待どおりに機能するかどうかを確認します。あなたはそれが壊れたとき - あなたは間違いなくそれが(**デバッグ**と呼ばれる)の原因の正確な部分を知っている – zerkms