Jquery plug-ins are rich and many of them are very useful. I recently learned how to create jquery plug-ins and found that jquery plug-ins are actually very simple. Here I will introduce them. Basic Format of jquery plug-in:
The Code is as follows:
(Function ($ ){
$. Fn. tab = function (options) {// The tab next to $. fn is the function name of this plug-in. You can make changes as you like.
Var defaults = {
// Related property settings
}
Var options = $. extend (defaults, options );
This. each (function (){
// Implemented function settings });
};
}) (JQuery );
Here is a tab plug-in for me to complete the above Code
The Code is as follows:
(Function ($ ){
$. Fn. tab = function (options ){
Var defaults = {
Eventname: "click", // trigger event, click as click, and mousemove as mouse
Titlekeyid: "tabtitle", // switch ID
Sedcss: "sed", // CSS when selected
Nosedcss: "nosed" // CSS when not selected
}
Var options = $. extend (defaults, options );
This. each (function (){
Var tab = $ (this );
// Bind events
$ (Tab). find ("li"). bind (options. eventname, function (){
$ ("#" + Options. titlekeyid). find ("li"). attr ("class", options. nosedcss );
$ (This). attr ("class", options. sedcss );
$ ("#" + Options. titlekeyid + "info"). find ("p" ).css ("display", "none ");
$ ("#" + $ (This). attr ("id") + "info" ).css ("display", "block ");
// Individual JS capabilities are still limited, and the code is not well written.
});
});
};
}) (JQuery );
I think you have used some jquery plug-ins. Here I will look at the code used by the plug-ins:
(Code 2)
The Code is as follows: