(function($){ var privateFunction = function(){ } var methods = { init:function(options){ return this.each(function(){ var $this = $(this); var settings = $.data($this,"changeColor"); console.log(settings,1); if(typeof (settings)=="undefined"){ var defaults = { color:"red", fontSize:"20px", paddingRight:"10px" }; settings = $.extend({},defaults,options); console.log(settings,2); }else{ settings = $.extend({},settings,options); } return $this.css({ color:settings.color, fontSize:settings.fontSize }); }); }, destroy:function(options){ return this.each(function(){ $this = $(this); $this.removeData("changeColor"); }); } } $.fn.changeColor = function(){ var method = arguments[0]; if(methods[method]){ method = methods[method]; arguments = Array.prototype.slice.call(arguments,1); }else if(typeof(method)=="Object"||!method){ method = methods.init; }else{ $.error('Method'+method+'does not exist on jQuery.changeColor'); return this; } return method.apply(this,arguments); } })(jQuery);
需要这种模式开发的轮播插件,练习用