Template:
(function ($) {
$.fn.plugins=function (options) {
var defaults = {
}
var options = $.extend (defaults,options);
This.each (function () {
})
}
return this;
}) (JQuery);
Example: Make a tab tab switch plugin
<div class= "tab" >
<ul class= "Tabnav" >
<li class= "Current" >html</li>
<li>css</li>
<li>js</li>
</ul>
<div class= "Tabcontent" >
<div style= "Display:block" >html</div>
<div>css</div>
<div>js</div>
</div>
</div>
<style>
*{padding:0;margin:0}
. Tabnav li{float:left;width:150px;height:26px;line-height:26p x;text-align:center;margin-right:3px;border:1px Solid Blue;border-bottom:none;list-style:none;cursor:pointer}
. Tabcontent{clear:both}
. tabcontent div{border:1px Solid blue;display:none;width:500px;height:200px}
. Tabnav Li.current{background:blue;color:white;font-weight:bold}
<script>
$.fn.tab=function (options) {
var defaults = {
Currentclass: "Current",
EventType: "Click",
Tabnav: ". Tabnav>li",
Tabcontent: ". Tabcontent>div"
}
var options = $.extend (defaults,options);
This.each (function () {
var _this = $ (this);
_this.find (Options.tabnav). Bind (Options.eventtype,function () {
$ (this). addclass (Options.currentclass). Siblings (). Removeclass (Options.currentclass)
var index = $ (this). index ();
_this.find (options.tabcontent). EQ (index). Show (). siblings (). Hide ()
})
})
return this;
}
}) (JQuery);
jquery Plugin Maker