jquery Plugin Development

Source: Internet
Author: User

It was not until recently that a small feature was written that Brainwave thought of trying to write plugin development that I wanted to do long ago. More depressed is, until the writing plug-in, only a deep understanding of what is called object-oriented! (Do not know how to think, I in the QQ space to send this sentence when everyone commented, "Take off a single?" "Is there an object?" "What's more," I understand, the programmer's object is the code, "This is not virtual." )

Reference a lot of online information, and then compare, and finally refer to Liu Yongyong's blog (http://www.cnblogs.com/Wayou/p/jquery_plugin_tutorial.html) to get the first simple plugin, Here is a record of the full plug-in format and related comments, to facilitate rapid development, sharing is happy.

// Here you can write the version number in the form of a comment, plug-in use, copyright, plugin use format, etc.
Plus Can prevent the preceding code from having no, the consequence of the end, without fear of compression
;(function($,window,document,undefined) {//Undefinde is a real undefined, not a parameter . //To pass a selectable variable to a method //defining Constructors (objects) vardatalist=function(ele,opt) { This. $element =Ele; This. defaults={ // define default properties ' Default property name ': ' corresponding attribute value ' }, This. Options=$.extend ({}, This. defaults, opt); The $.extend () function is automatically executed when used, allowing the user-defined property value to override the default property value. The {} null object is preceded by a default property value modified to prevent previous property values from being called multiple times
  
Here you can add some common property methods for use in several methods
}
//defined on the object prototypemethod, unlimited number ofDatalist.prototype={showlist:function(){ varColor= This. Options.bgcolor; // value of the transfer form (preferably here to take out all the necessary, after all, under different circumstances this refers to the same)         
Here is the specific implementation process writing area
return This; //return is designed to not break the features of the jquery chain call (note that the return object is the original object), or you can callback a function as a return value } }
//using the DataList object in a plug- in$.fn.mydatalist=function(options) {//Create entity vardatalist=NewDatalist ( This, Options); //In the form of a return value callcall its method returndatalist.showlist (); }}) (Jquery,window,document); //actually is (function () {} ()), the closure of the form, the definition of anonymous functions and immediate invocation, the event binding inside the same as in the global definition of the same can be used (when the page is closed to destroy), but the global space is not visible unreachable


Call the plug-in where needed
$ (document). Ready (function () {
Properties that are not set are used with default values
});

I can write so many Caishuxueqian, copy and paste renaming can be directly applied. If you want to get specific, more content (such as how to publish a jquery plugin) please see the link above Liu Yongyong (anyway I have to thank him ...) )。 If there is any problem with the annotations in this, please let me know, thank you!

Next is a few days I rewrite the common plug-in (previously is process-oriented, write once ... ), hoping to help the same rookie as me.

jquery Plugin Development

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.