我做错了什么?它在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