One, the expansion of the global function
The global function is to add a standalone function to the jquery namespace Central. When used, it can be called by $.fucnname (param) or jquery.funcname (param).
1. Add directly to jquery: Add a global function to jquery SayHello
jquery.sayhello=function(name) {alert (name+"Hello");};
Call Mode:
Jquery.sayhello ("Zhang Zihan"); //or with $.sayhello ("Zhang Zihan") ;
2, Jquery.extend (): Its function is to use one or more objects to extend an object, returning the object being extended.
2.1 Jquery.extend (Dsc,src1,src2 ...): Extends Src1,src2 to a DSC object and returns the expanded DSC object (merge Object)
2.2 Jquery.extend (object): Extends the jquery namespace itself, as a result of adding functions to the jquery namespace.
//Add two functions to the jquery namespace. jquery.extend ({ functionreturn a < b a:b;}, functionreturn a > B? A:B; }});
Invocation mode
//= 2Jquery.max (4,5); = 5
Ii. extension of the object method
The extension of an object method allows all jquery objects to invoke the method.
1, Jquery.fn
//Add the SayHello method on a jquery object jquery.fn.sayhello=function(name) {alert (name+"Hello");}
Call
$ ("div"). SayHello ("Dwqs");
2, JQuery.fn.extend
Extend the JQuery element set to provide new methods (often used to make plugins).
//Add two plugin methods. jQuery.fn.extend ({check: function() { return this. . checked = true; }); }, Uncheck: function() { return this. All (function() { this. Checked = false; }); }});
Call:
$ ("Input[type=checkbox]"). Check (); $ ("Input[type=radio]"). Uncheck ();
In the next note, you'll use a simple example to illustrate how to develop plugins in this way.
Original starting: http://www.ido321.com/1330.html
Next: The mathematical Principles of search and page ranking
Dom Note (vi): How do I do a jquery extension?