Teach you to write jquery plugins

Source: Internet
Author: User

recently, many netizens sayJqueryWhat is a plugin? How do you write that? I can't write?
a lot of questions do not know how to answer them at the moment, the personal think is the netizen to complicate the problem.
In fact, some of the commonly used, practical, universal functions encapsulated and, in short, is to put these code in a method, you can achieve the effect of repeated use, so that you do not need to use this function every time to write again.
now jquery is added to the concept of plug-ins, as long as it is in accordance with its specific format as usual writing function to write it, not though it is too complex. Believe it or not, I believe it anyway.
next with a simple code to explain, if the netizens have read the plugin will not write, I can only no language
First step: Define the plugin



  1. $ (function () {

  2. $.fn. Plug-in name = function (options) {

  3. var defaults = {

  4. Event: "Click",//Trigger response Event

  5. Msg: "Holle word!"//display content

  6. };

  7. var options = $.extend (defaults,options);

  8. var $this = $ (this); Of course the response event object

  9. Function Code Section

  10. Binding events

  11. $this. Live (options. Event,function (e) {

  12. alert (options.msg);

  13. });

  14. }

  15. });
  16. Copy Code
Copy Code
Step Two: Call the plugin



  1. $ (function () {

  2. Binding element Events

  3. $ ("#test"). Plug-in name ({

  4. Event: "Click",//Trigger response Event

  5. msg: "The plugin turned out to be so simple!"//display content

  6. });

  7. });

  8. <input type= "button" id= "Test" value= "This is a simple plug-in call"/>
  9. Copy Code
Copy Code
after reading, I believe that netizens should understand it! jquery Plugin is so simple original addresshttp://www.00h5.com/thread-2097-1-1.html

Teach you to write 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.