/**
* Plug-in learning
* Original address: Http://www.cnblogs.com/Wayou/p/jquery_plugin_tutorial.html#home
*/
;(function ($, window, document,undefined) {
To define the Beautifier constructor
var beautifier = function (Ele, opt) {
this. $element = Ele,
This.defaults = {
' Color ': ' Red ',
' FontSize ': ' 12px ',
' textdecoration ': ' None '
},
This.options = $.extend ({}, this.defaults, opt)
}
Methods for defining Beautifier
Beautifier.prototype = {
Beautify:function () {
return this. $element. css ({
' Color ': This.options.color,
' FontSize ': this.options.fontSize,
' TextDecoration ': this.options.textDecoration
});
}
}
Using the Beautifier object in a plug-in
$.fn.myplugin = function (options) {
Create a Beautifier entity
var beautifier = new Beautifier (this, options);
Call its method
return beautifier.beautify ();
}
}) (JQuery, window, document);
The writing of jquery plugins