jquery plug-in development is divided into two types:
1 class level
Class level you can understand that to extend the jquery class, the most obvious example is $.ajax (...), which is equivalent to a static method.
The $.extend method, i.e. Jquery.extend (object), is used when developing its methods;
$.extend ({
Add: function (a,b) {return a+b;},
minus: function (a,b) {return a-b;}
});
Page Call:
var i = $.add (3,2);
var j = $.minus (3,2);
2 Object Level
The object level can be understood as an object based extension, such as $ ("#table"). ChangeColor (...); Here this ChangeColor, is based on the expansion of the object.
The $.fn.extend method, i.e. JQuery.fn.extend (object), is used when developing its methods;
$.fn.extend ({
Check: function () {
Return This.each ({
This.checked=true;
});
},
uncheck: function () {
Return This.each ({
This.checked=false;
});
}
});
Page Call:
$ (' input[type=checkbox] '). Check ();
$ (' input[type=checkbox] '). Uncheck ();
3, Extended
$.xy = {
Add:function (a,b) {return a+b;},
Minus:function (a,b) {return a-b;},
Voidmethod:function () {alert (' void ');}
};
var i = $.xy.add (3,2);
var m = $.xy.minus (3,2);
$.xy.voidmethod ();
Article from: http://blog.csdn.net/woshixuye/article/details/7246735