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