我做錯了什麼?它在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);
工作一切「它的工作之前,我分離方法」 ---回滾代碼到它的工作狀態。再次重複同樣的步驟,逐行進行。每次微小的迭代後,檢查一切是否按預期工作。當你弄壞它時 - 你肯定知道究竟是什麼原因引起的一小部分變化(它被稱爲**調試**) – zerkms 2012-03-21 22:08:33