Jquery provides two methods for development plug-ins: Jquery. FN. Extend (object ); Jquery. Extend (object ); Jquery. Extend (object); adds a new method to the class to extend the jquery class itself. Jquery. FN. Extend (object); add a method to the jquery object. What is fn. View jqueryCodeIt is not difficult to find out.
Jquery. fn = jquery. Prototype = { Init: function (selector, context ){//.... //...... }; It turns out that jquery. fn = jquery. prototype. It is certainly no stranger to prototype. Although JavaScript does not have a clear concept of a class, it is more convenient to use a class to understand it. Jquery is a well-encapsulated class. For example, we use the statement $ ("# btn1") to generate a jquery class instance. Jquery. Extend (object); adding class methods to the jquery class can be understood as adding static methods. For example: $. Extend ({ Add: function (a, B) {return a + B ;} }); Add a "static method" for jquery as add, and then you can use this method in the place where jquery is introduced, $. Add (3, 4); // return 7 Jquery. FN. Extend (object); the extension to jquery. prototype is to add "member functions" to the jquery class ". Jquery class instances can use this "member function ". For example, we want to develop a plug-in and create a Special edit box. When it is clicked, the content in the current edit box of alert is displayed. You can do this: Java code
-
- $. FN. Extend ({
-
- Alertwhileclick: function (){
-
- $ ( This ). click (function () {
-
- alert ($ ( This ). val ();
- });
-
- }
-
- });
-
- $ ("# Input1"). Alertwhileclick ();// <Input id = "input1" type = "text"/>
$ ("# Input1") is a jquery instance. When it calls the member method alertwhileclick, the extension is implemented. When it is clicked, the content in the current edit is displayed. In the real development process, of course, we will not do such a small plug-in. In fact, jquery has provided a wide range of operations.CompositionFile, event, CSS, Ajax, and effect methods can be combined to develop more niubility plug-ins. |