In actual application, you can add N similar tabs as needed to ensure the integrity of the structure code of the tab module, you do not need to manually bind an event handler to HTML and add an ID to the content layer to hide the display.
The Javascript (jquery) code is as follows:
Copy codeThe Code is as follows:
<Script language = "javascript" type = "text/javascript">
$ (Document). ready (function (){
$ ("Ul. menu li: first-child"). addClass ("current ");
$ ("Div. content"). find ("div. layout: not (: first-child)"). hide ();
$ ("Div. content div. layout "). attr ("id", function () {return idNumber ("No") + $ ("div. content div. layout "). index (this )});
$ ("Ul. menu li"). click (function (){
Var c = $ ("ul. menu li ");
Var index = c. index (this );
Var p = idNumber ("No ");
Show (c, index, p );
});
Function show (controlMenu, num, prefix ){
Var content = prefix + num;
$ ('#' + Content). siblings (). hide ();
$ ('#' + Content). show ();
ControlMenu. eq (num). addClass ("current"). siblings (). removeClass ("current ");
};
Function idNumber (prefix ){
Var idNum = prefix;
Return idNum;
};
});
</Script>
The CSS style code is as follows:
Copy codeThe Code is as follows:
<Style type = "text/css">
* {Margin: 0; padding: 0}
Ul, li {list-style: none}
. Box {width: pixel PX; height: 150px; border: 1px solid # ccc; margin: 10px; font-size: 12px; font-family: Verdana, Arial, Helvetica, sans-serif}
. TagMenu {height: 28px; line-height: 28px; background: # efefef; position: relative; border-bottom: 1px solid #999}
. TagMenu h2 {font-size: 12px; padding-left: 10px ;}
. TagMenu ul {position: absolute; left: 100px; bottom:-1px; height: 26px ;}
Ul. menu li {float: left; margin-bottom: 1px; line-height: 16px; height: 14px; margin: 5px 0 0-1px; border-left: 1px solid #999; text-align: center; padding: 0 12px; cursor: pointer}
Ul. menu li. current {border: 1px solid #999; border-bottom: none; background: # fff; height: 25px; line-height: 26px; margin: 0}
. Content {padding: 10px}
</Style>
The HTML Structure Code is as follows:
Copy codeThe Code is as follows:
<Body>
<Div class = "box">
<Div class = "tagMenu">
<H2> No.1 Menu <Ul class = "menu">
<Li> Label 1.1 </li>
<Li> Label 1.2 </li>
<Li> Label 1.3 </li>
<Li> Label 1.4 </li>
</Ul>
</Div>
<Div class = "content">
<Div class = "layout"> infomation 1.1 </div>
<Div class = "layout"> infomation 1.2 </div>
<Div class = "layout"> infomation 1.3 </div>
<Div class = "layout"> infomation 1.4 </div>
</Div>
</Div>
<Div class = "box">
<Div class = "tagMenu">
<H2> No. 2 Menu <Ul class = "menu">
<Li> Label 2.1 </li>
<Li> Label 2.2 </li>
<Li> Label 2.3 </li>
<Li> Label 2.4 </li>
</Ul>
</Div>
<Div class = "content">
<Div class = "layout"> infomation 2.1 </div>
<Div class = "layout"> infomation 2.2 </div>
<Div class = "layout"> infomation 2.3 </div>
<Div class = "layout"> infomation 2.4 </div>
</Div>
</Div>
</Body>