Writing jquery Plugins

Source: Internet
Author: User

First, class level ($.extend)

Class level you can understand that to expand the jquery class, the most obvious example is $.ajax (...), which is equivalent to a static method.

The $.extend method is used when developing its methods, i.e. jquery.extend (object);

Second, the object level

The object level can be understood as an object-based extension, such as $ ("#table"). ChangeColor (...); Here this ChangeColor, is based on the expansion of the object.

The $.fn.extend method is used when developing its methods, i.e. jQuery.fn.extend (object);

Third, jquery plug-in development process

1, define the scope: to define a private scope for the plug-in, external code can not directly access the code inside the plug-in, plug-in internal code does not pollute the global variables,

2. Extend a plugin for jquery: Add a spread method to the instance of jquery. The spread method can receive some parameters.

3, set default value: Set default value for extension method, the default Property object is generally defined as defaults. Use $.extend (defaults,options) to merge the default values with the passed-in parameters

4, support for jquery connection call: Loop to return each element.

5, plug-in method: In order to make the code structure visualization, need to use function. The method in the plugin cannot be called by the outside world.

6. Custom callback function: Use call and apply method to execute callback function,

Writing jquery Plugins

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.