<! DOCTYPE HTML PUBLIC "-//w3c//dtd HTML 4.01 transitional//en" "HTTP://WWW.W3.ORG/TR/HTML4/LOOSE.DTD" >
<meta http-equiv= "Content-type" content= "text/html; Charset=utf-8 ">
<title>jquery custom Tab Plugin </title>
<style>
Body, ul {padding:0; margin:0;}
Li {list-style:none;}
#tabs {zoom:1;}
#tab: After {content: ""; Display:block; Clear:both; }
#tabs li {float:left padding:10px; color: #FF8900; background: #FFF; cursor:pointer;}
#tabs. Active {background: #FF8900; color: #FFF;}
#tabContent {background: #FF8900; color: #FFF; padding:10px; clear:both;}
#tabContent div {display:none;}
#tabContent div.active {Display:block}
</style>
<body>
<ul id= "Tabs" >
<li data-tab= "Users" >Users</li>
<li data-tab= "Groups" >Groups</li>
</ul>
<div id= "Tabcontent" >
<div data-tab= "Users" >users content</div>
<div data-tab= "groups" >groups content</div>
</div>
<script src= "Http://code.jquery.com/jquery-1.9.1.min.js" ></script>
<script>
JQuery.fn.tabs = function (Control) {
var element = $ (this);
var control = $ (control);
Element.delegate (' Li ', ' click '), function () {
Traverse Tab Name
var tabname = $ (this). attr (' Data-tab ');
Trigger custom event when clicking on a tab
Element.trigger (' Change.tabs ', tabname);
});
Binding to custom events
Element.bind (' Change.tabs ', function (EV, tabname) {
Element.find (' Li '). Removeclass (' active ');
Element.find (' >[data-tab= ' + tabname + '] '). addclass (' active ');
});
Element.bind (' Change.tabs ', function (EV, tabname) {
Control.find (' >[data-tab] '). Removeclass (' active ');
Control.find (' >[data-tab= ' + tabname + '] '). addclass (' active ');
});
Activate the 1th tab
var firstName = element.find (' Li:first '). attr (' Data-tab ');
Element.trigger (' Change.tabs ', firstName);
return this;
};
JQuery (function ($) {
$ (' #tabs '). Tabs (' #tabContent ');
$ (' #tab '). Bind (' Change.tabs ', function (EV, tabname) {
Window.loaction.hash = tabname;
});
$ (window). bind (' Hashchange ', function () {
var tabname = Window.location.hash.slice (1);
$ (' #tabs '). Trigger (' Change.tabs ', tabname);
});
});
</script>
</body>