The $.fn $.fx in jquery

Source: Internet
Author: User

$.fn refers to the
The jquery namespace, along with the methods and properties on FN, is valid for every jquery instance. such as extension $.fn.abc () then you can look like this: $ ("#div"). ABC (); Often use the Extend method extension, see the API for details. $.fx refers to the
  
The special effects of jquery. If you use display, swipe, fade, animate, and so on.      $.fx.off can turn off the animation, in fact, the results are displayed directly. JQuery's extend and fn.extendjquery for the development of the plug-in two methods, namely: JQuery.fn.extend (object); Jquery.extend (object) ;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. Jquery.fn = Jquery.prototype = {Init:function (selector, context) {//...};

The original Jquery.fn = Jquery.prototype. It's certainly not strange to prototype.

Although JavaScript does not have a clear class concept, it is more convenient to use a class to understand it.

jquery is a well-encapsulated class, such as we use the statement $ ("#btn1") to generate an instance of the jquery class. J

Query.extend (object); Adding a class method to the jquery class can be understood as adding a static method. such as: $.extend ({add:function (A, b) {return a+b;}});

Adds a "static method" for jquery to add, which can then be used 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.

An instance of the jquery class can use this "member function". For example, we want to develop a plugin, make a special edit box, when it is clicked, then alert the contents of the current edit box.

You can do this: Java code $.fn.extend ({alertwhileclick:function () {$ (this). Click (function () {alert (the This). Val ());});});

$ ("#input1"). Alertwhileclick (); On the page: <input id= "INPUT1" type= "text"/>
$ ("#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.

The real development process, of course, do not make such a small white plug-in, in fact, jquery arch a wealth of operating documents, events, CSS, Ajax, effects of methods, combined with these methods, you can develop more niubility plug-ins.

jquery (function () {}) differs from (function () {} (jquery) by 1.first jquery (function () {}) and full write as jquery (DOCUNEMT). Ready (function () { }); The meaning is to execute the Ready () Method 2 after the DOM is loaded. (Funtion () {} (jquery); the actual execute () (para) anonymous method, except that the JQuery object is passed.

Summary: JQuery (Funtion () {}); The code used to hold the DOM object, the DOM object already exists when executing code. cannot be used to store development plug-in code.

The $.fn $.fx in jquery

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.