Practice and improvement: Compile the jQuery plug-in

Source: Internet
Author: User

JQuery brings us great convenience in writing web applications. Many jQuery plug-ins are favored by users. Basically, the jQuery plug-in is written in the structure of anonymous functions, and jQuery objects are introduced as parameters.

The following is an implementation of the most basic jQuery plug-in. Knowledge point:

In the jQuery anonymous function, jQuery. extend (); method is used to create the jQuery plug-in.

In jQuery anonymous functions, the jQuery plug-in is created using the object. Property = function method.

<! --

The simplest jquery plugin

Hu Kaiming

-->

<! Doctype html public "-// W3C // dtd html 4.01 Transitional // EN">

<Html>

<Head>

<Title> simplest jquery plug-in </title>

<Meta http-equiv = "Content-Type" content = "text/html; charset = UTF-8">

<Script type = "text/javascript" src = "../res/jquery/jquery-1.4.4.min.js"> </script>

<Script type = "text/javascript">

(Function ($ ){

JQuery. extend ({// write method 1

A: function (h ){

$ ("# Ad" example .html (h );

},

B: function (h ){

Alert (h );

}

})

}) (JQuery );

 

(Function ($) {// Statement 2

JQuery. a = function (h ){

$ ("# Ad" example .html (h );

}

JQuery. B = function (h ){

Alert (h );

}

}) (JQuery );

 

$ (Document). ready (function (){

$. A ("abc ");

$. B ("xyz ");

});

 

</Script>

 

</Head>

<Body>

<H3> simplest jQuery plug-in

<Div id = "ad"> </div>

</Body>

</Html>

 

From the wj800 Column

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.