jquery has two methods for developing plug-ins, namely:
JavaScript code
Jquery.extend (object); To extend the jquery class itself. Adds a new method to the class.
JQuery.fn.extend (object); Adds a method to a jquery object.
What's the FN thing? If you look at the jquery code, it's not hard to find.
JavaScript code
Jquery.fn = jquery.prototype = {init: (selector, context) {// .... // };
< Span class= "Apple-converted-space" >< Span class= "Apple-converted-space" > original Jquery.fn = Jquery.prototype. It must be no stranger to prototype. &NBSP;
Although JavaScript does not have an explicit class concept, it is more convenient to use classes to understand it. &NBSP;
jquery is a well-encapsulated class, such as we use the statement $ ("#btn1 ″") to generate an instance of the jquery class. &NBSP;
Jquery.extend (object); Add class method for JQuery class can be understood as adding a static method . such as: &NBSP;
xml/html code &NBSP;
$.extend ({add:function(A, b) {return A +
Adds a "static method" for jquery to add, which can then be used where jquery is introduced,
JavaScript code
$.add (3,4); // return 7
< Span class= "Apple-converted-space" >< Span class= "Apple-converted-space" >< Span class= "Apple-converted-space" >< Span class= "Apple-converted-space" >jquery.fn.extend (object); The extension to Jquery.prototype is to add "member functions" to the jquery class. An instance of the jquery class can use this "member function". &NBSP;
For example, we want to develop a plugin, make a special edit box, when it is clicked, it will alert the contents of the current edit box. You can do this: &NBSP;
JavaScript code
$.fn.extend ({alertwhileclick:function() {$ (this). Click (function () {alert (this). Val ());
This can be written at the time of the call:
//
< Span class= "Apple-converted-space" >< Span class= "Apple-converted-space" >< Span class= "Apple-converted-space" >< Span class= "Apple-converted-space" >< Span class= "Apple-converted-space" >$ ("#input1 ″") is a jquery instance, and when it calls the Member method alertwhileclick it implements the extension, which pops up the contents of the current edit each time it is clicked. &NBSP;
the real development process, of course, will not do such a small white plug-in, in fact, jquery arch a wealth of operational documents, events, CSS, Ajax, Effect of the method, With these methods, more niubility plugins can be developed. &NBSP;
Note: &NBSP;
There is a special place here, where the function begins with jquery.extend = JQuery.fn.extend, and the Jquery.prototype is assigned to Jquery.fn in front of the program, so call in the following It is important that this is reflected everywhere in the Jquery.js .
Jquery.fn.extend and Jquery.extend