Jquery plug-in development general framework, jquery plug-in framework

Source: Internet
Author: User

Jquery plug-in development general framework, jquery plug-in framework

Jquery plug-in development framework code:

/** INS: * 1. Plug-In Name: jquery. [plug-in name]. js, such as jquery. plugin. js * 2. Add the object method to jQuery. on fn, add the global method to the jQuery object itself. * 3. this inside the plug-in points to the jQuery object obtained through the selector * 4. You can use this. each traverses all elements * 5. All methods end with a semicolon. Add a semicolon * 6 to the plug-in header. The plug-in should return a jQuery object, to ensure the chained operation of the plug-in * 7. Use the closure form, and use $ as the alias of jQuery to avoid conflicts * // for good compatibility, there is a semicolon before the start; // The jQuery object is passed in to ensure that the jQuery object is used correctly in the anonymous function and prevent the $ conflict when multiple libraries coexist. // it is not required to pass in the window and document, however, in order to access the window and document more quickly, the undefined parameter is not modified because the parameter is not actually passed. (Function ($, win, doc, undefined) {var alertPlugin = function (opts) {// save this variable var _ self = this; // define the default parameter _ self. opts = {content: 'pop-up content'}; // extend the default parameter if (opts & $. isPlainObject (opts) {$. extend (_ self. opts, opts);} // call Function Method _ self. show (_ self. opts) ;}; // function method implementation alertPlugin. prototype = {show: function (opts) {alert (opts. content) ;}} // extension plug-in $. fn. extend ({alertPlugin: function (opts) {// traverse all elements return this. each (function () {new alertPlugin (opts) ;}}) ;}) (jQuery, window, document); // jQuery, window, and document are real parameters.

Plug-in call:

// Call without passing parameters $ ('. A '). alertPlugin (); // call the passed parameter $ ('. A '). alertPlugin ({content: 'New pop-up content '});

 

Related Article

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.