Jquery $. fn $. fx what does it mean? _ jquery-js tutorial

Source: Internet
Author: User
$. Fn refers to the namespace of jquery. Adding Methods and attributes on fn will be effective for each jquery instance. The following describes jquery $. fn $. what is fx? $. fn refers to the namespace of jquery. Adding Methods and attributes on fn will be effective for each jquery instance.
For example, extend $. fn. abc ()
Then you can: $ ("# p"). abc ();
Extends are usually used. For more information, see the API.
$. Fx is the special effect of jquery.
Display, slide, fade-in and fade-out, and animation are used.
$. Fx. off can be used to close the animation and display the result directly.

Extend and fn. extend of jquery

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. It is not difficult to see jQuery code.
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:

Jquery code:

The Code is as follows:


$. Fn. extend ({
AlertWhileClick: function (){
$ (This). click (function (){
Alert ($ (this). val ());
});
}
});
$ ("# Input1"). alertWhileClick ();


On the page:
$ ("# 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, there will not be such a small plug-in. In fact, jQuery has provided a wide range of operations documents, events, CSS, Ajax, and effects methods, combined with these methods, you can develop more Niubility plug-ins.

Differences between jquery (function () {}) and (function () {} (jQuery)
1.
JQuery (function (){});
Write All
JQuery (docunemt). ready (function (){
});
It means to execute the ready () method after DOM loading.
2.
(Funtion (){
} (JQuery );
The actual execution of the () (para) anonymous method only passes the jQuery object.

Conclusion: jQuery (funtion () {}); is used to store the code of the DOM object. When the code is executed, the DOM object already exists. It cannot be used to store development plug-in code. Because the jQuery object is not passed, the method cannot be called externally through jQuery. methodye.
(Funtion (){
} (JQuery );
It is used to store the code of the Development plug-in. The Code DOM does not necessarily exist during execution. Please use it with caution when executing the DOM operation code directly.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.