10 minutes to learn how to write Jquery plug-in instance tutorial _ jquery-js tutorial

Source: Internet
Author: User
This article mainly introduces how to write Jquery plug-ins in 10 minutes. It is very practical to complete a simple plug-in two steps through an instance, for more information, see jquery plug-ins. Many of my friends have used jQuery plug-ins, but few have written jQuery plug-ins on their own. This article briefly describes the implementation method of jquery plug-ins in the form of examples. Share it with you for your reference. The specific method is as follows:

Specifically, some common, practical, and general functions are encapsulated. Simply put, these codes are put in a method to achieve repeated use, in this way, you do not need to re-write each time you use this function.

Now Jquery has added the plug-in concept, as long as it is written in the same way as function writing in its specific format. It is not complicated. Believe it or not, but I believe it.

Next, I will explain it with simple code. If you have read the plug-in, I will only be speechless.

The procedure is as follows:

Step 1: Define the plug-in

$ (Function () {$. fn. Plug-in name = function (options) {var defaults = {Event: "click", // trigger the RESPONSE Event msg: "Holle word! "// Display content}; var options = $. extend (defaults, options); var $ this = $ (this); // Of course, the response to the event object // feature code section // bind the event $ this. live (options. event, function (e) {alert (options. msg );});}});

Step 2: Call the plug-in

$ (Function () {// bind element event $ ("# test "). plug-in name ({Event: "click", // trigger the RESPONSE Event msg: "plug-in is so simple! "// Display content });});

This is the simplest plug-in! Less than 10 minutes! I believe everyone should have understood it! JQuery plug-in is so simple.

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.