<! DOCTYPE html>
<meta charset= "Utf-8" >
<meta http-equiv= "x-ua-compatible" content= "ie=edge,chrome=1" >
<meta name= "viewport" content= "width=device-width; initial-scale=1.0; minimum-scale=1.0; maximum-scale=2.0 "/>
<title> tab-leaf making </title>
<meta name= "description" content= "JS tab"/>
<meta name= "keywords" content= "leaves"/>
<style type= "Text/css" >
*{padding:0; margin:0; border:none;list-style:none;}
body{width:800px;margin:50px Auto;}
. Tab{width:800px;color: #fff; text-align:center;}
. tab. Tit{overflow:hidden;}
. tab. Tit li{display:inline-block;float:left;margin-right:10px;width:100px;height:30px;line-height:30px; Background:blue;}
. tab. Tit li.on{background:red;}
. Tab>div{display:none;width:800px;height:300px;line-height:300px;background:red;font-size:80px;font-weight: Bold;}
. Tab>div.on{display:block;}
</style>
<body>
<div id= "tab1" class= "tab" >
<ul class= >
<li>111</li>
<li>222</li>
<li>333</li>
</ul>
<div>111</div>
<div>222</div>
<div>333</div>
</div>
<div id= "tab2" class= "tab" >
<ul class= >
<li>111</li>
<li>222</li>
<li>333</li>
</ul>
<div>111</div>
<div>222</div>
<div>333</div>
</div>
<script type= "Text/javascript" >
Function tab (TABID) {
var tab = document.getElementById (tabId);
var olis = tab.getelementsbytagname ("Li");
var odiv = tab.getelementsbytagname ("div");
Olis.item (0). ClassName = "on";//Add class name to Li[0];
Odiv.item (0). ClassName = "on";//Add class name to Div[0];
for (Var i=0;i<olis.length;i++) {
Olis.item (i). Wkxindex = i;//custom attributes;
Olis.item (i). onclick = function () {//click Li;
for (Var i=0;i<olis.length;i++) {//Use the loop to set all the on class names on Li and div to null when you click on Li;
Olis.item (i). ClassName = null;
Odiv.item (i). ClassName = null;
}
Olis.item (this.wkxindex). ClassName = "on";//use a custom attribute to put the given class name of the current click on (add Style);
Odiv.item (this.wkxindex). ClassName = "on";
}
}
}
tab ("TAB1");//pass the ID value of the div using the tab;
tab ("TaB2");
</script>
</body>
Native JS Implementation Tab effect