Examples of $.FN usage in jquery are _jquery

Source: Internet
Author: User
$.fn refers to the jquery namespace, plus the methods and properties on FN, which are valid for each of the jquery instances.
If the extension $.fn.abc (), that is, $.FN.ABC () is an ABC method extended to jquery, then each of your jquery instances can be referenced in the following way.
Then you can look like this: $ ("#div"). ABC ();

jquery has two methods for developing Plug-ins, respectively:

Jquery.extend (object); To extend the jquery class itself. Adds a new method to the class.
JQuery.fn.extend (object); Add methods to the JQuery object.

What is FN? See the jquery code, it's not hard to find.
Copy Code code as follows:

Jquery.fn = Jquery.prototype ={
Init:function (Selector, context) {//....
//......
};

Originally JQUERY.FN =jquery.prototype. To prototype certainly not strange.
jquery is a very nicely encapsulated class, for example, we use statement $ ("#btn1") to generate an instance of a jquery class.

Jquery.extend (object); Adding a class method to the jquery class can be understood as adding a static method. Such as:
Copy Code code as follows:

$.extend ({
Add:function (a,b) {returna+b;}
});

Add a "static method" for jquery, and then you can use this method in the place where jquery is introduced,
$.add (3,4); Return 7

JQuery.fn.extend (object), and extending to Jquery.prototype, is to add a "member function" for the jquery class. Examples of jquery classes can use this "member function".
For example, we want to develop a plugin, make a special edit box, when it is clicked, alert the contents of the current edit box. Can do this:

jquery Code
Copy Code code as follows:

$.fn.extend ({

Alertwhileclick:function () {

$ (this). Clic K (function () {

Alert ($ (this). Val ());
});
}
});

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.