jQuery , . , $.fn . , - :
$.fn.yourPlugin = function(options) {
if (typeof options === "string") {
} else {
}
};
: Plugin.prototype. , changeColor:
Plugin.prototype.changeColor = function(color) {
$(this.element).css("color", color);
}
$(this.element). , Plugin element, , :
this.element = element;
DOM, jQuery, jQuery .
, , . jQuery:
$.fn[pluginName] = function ( options ) {
return this.each(function () {
if (typeof options === "string") {
var args = Array.prototype.slice.call(arguments, 1),
plugin = $.data(this, 'plugin_' + pluginName);
plugin[options].apply(plugin, args);
} else if (!$.data(this, 'plugin_' + pluginName)) {
$.data(this, 'plugin_' + pluginName,
new Plugin( this, options ));
}
});
};
changeColor :
$("#example").defaultPluginName("changeColour", "red");βββββββββββββββββββββββββββ
. , , , (), .