I chose jquery, the most important is its thinking "write Less,do more", because I am a picky person, the previous written code, will be turned out from time to time to see if there can be streamlined, optimized place. One is the promotion of continuous learning, and secondly can be new ideas, technology applied to the inside.
The jquery plug-in writing, has been introduced before, there are many examples on the Internet. Here's a quick way to do this, mainly for shorthand, see the following code:
<script type= "Text/javascript" src= "Jquery-1.4.2.js" ></script>
Copy Code code as follows:
<script type= "Text/javascript" >
jquery plug-in notation (requires incoming action object)
;(function ($)
{
Pi_testplugin is the plug-in name and is the action object of the plug-in
In order not to repeat with other plugin names, I use plugin's abbreviated PI_ to define the plugin object prefix
$.fn. pi_testplugin=
{
Basic information for this plugin
info:{
Name: "Testplugin",
Ver: "1.0.0.0",
Corp: "Lzhdim",
Author: "Lzhdim",
Date: "2010-01-01 08:00:00",
Copyright: "Copyright @ 2000-2010 Lzhdim Technology Software all Rights Reserved",
License: "GPL"
},
A function object with parameters, where the argument is an object, with attributes
Functionwithparams:function (Paramobj)
{
Use parameters, whether default values are used
var params = paramobj? Paramobj:new function () {
param1= "1";
Param2= "2";
};
return This.Info.Name + ". Functionwithparamobject ";
},
A function object with parameters, where the argument is a variable
Functionwithparam:function (Varparam)
{
Use parameters, whether default values are used
var param = Varparam? Varparam:null;
return This.Info.Name + ". Functionwithparam ";
},
function objects that do not have parameters
Functionwithoutparam:function ()
{
return This.Info.Name + ". Functionwithoutparam ";
}
};
}) (JQuery);
jquery extension function (no need for incoming action object), i.e. API function
;(function ($)
{
$.extend ({
Pif_testextendfunction as an operational object of extended function
In order not to repeat with other plugin names, I use plugin's abbreviated PI_ to define the plugin object prefix
Pif_testextendfunction:
{
The basic information of the extended function
info:{
Name: "Testextendfunction",
Ver: "1.0.0.0",
Corp: "Lzhdim",
Author: "Lzhdim",
Date: "2010-01-01 08:00:00",
Copyright: "Copyright @ 2000-2010 Lzhdim Technology Software all Rights Reserved",
License: "GPL"
},
function object with parameters
Functionwithparams:function (Paramobj)
{
Use parameters, whether default values are used
var params = paramobj? Paramobj: {
param1: "1",
Param2: "2"
};
return This.Info.Name + ". Functionwithparamobect ";
},
A function object with parameters, where the argument is a variable
Functionwithparam:function (Varparam) {
Use parameters, whether default values are used
var param = Varparam? Varparam:null;
return This.Info.Name + ". Functionwithparam ";
},
function objects that do not have parameters
Functionwithoutparam:function ()
{
return This.Info.Name + ". Functionwithoutparam ";
}
}
});
}) (JQuery);
$ (function ()
{
Test Plug-in
var params =
{
PARAM1: "3",
PARAM2: "4"
};
Alert (this). Pi_testplugin.functionwithparams (params));
Alert ($. Pif_testextendfunction.functionwithoutparam ());
});
</script>