Jquery plug-in development

Source: Internet
Author: User

1.1 add static methods

    1. Jquery. Extend (object );

CopyCode

To expand the jquery class itself and add new methods to the class, you can understand how to add static methods.

    1. $. Extend ({
    2. Addmethod: function (a, B) {return a + B;} // $. addmethod (1, 2); // return 3
    3. });

Copy code

1.2 add member Method

    1. Jquery. FN. Extend (object );

Copy code

    1. Jquery. fn = jquery. Prototype

Copy code

Add a method to the jquery object, expand jquery. prototype, and add a member method to the jquery class:

    1. $. FN. Extend ({
    2. Getinputtext: function (){
    3. $ (This). Click (function (){
    4. Alert ($ (this). Val ());
    5. });
    6. }
    7. });
    8. $ ("# Username"). getinputtext ();

Copy code

2. A general framework:

The following is a general framework:

    1. (Function ($ ){
    2. $. FN. yourpluginname = function (options ){
    3. // Various attributes and Parameters
    4. VaR Options = $. Extend (defaults, options );
    5. This. Each (function (){
    6. // Implementation code of the plug-in
    7. });
    8. };
    9. }) (Jquery );

Copy code

About

    1. $. Extend (defaults, options );

Copy code

Ults is extended by merging defaults and options to implement the default Parameter Function of the plug-in. For details, refer to the official document of jquery:
Http://api.jquery.com/jQuery.extend/

Original article: http://www.itzhai.com/jquery-plug-ins-to-achieve-the-methods-and-principles-of-simple-instructions.html

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.