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;
Copy Code code as follows:
$.extend ({
Add:function (a,b) {return a+b;},
Minus:function (a,b) {return a-b;}
});
Page Call:
Copy Code code as follows:
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;
Copy Code code as follows:
$.fn.extend ({
Check:function () {
Return This.each ({
This.checked=true;
});
},
Uncheck:function () {
Return This.each ({
This.checked=false;
});
}
});
Page Call:
Copy Code code as follows:
$ (' input[type=checkbox] '). Check ();
$ (' input[type=checkbox] '). Uncheck ();
3, extended
Copy Code code as follows:
$.xy = {
Add:function (a,b) {return a+b;},
Minus:function (a,b) {Retu RN A-b;},
Voidmethod:function () {alert ("void");}
};
var i = $.xy.add (3,2);
var m = $.xy.minus (3,2);
$.xy.voidmethod ();