Core code:
Copy codeThe Code is as follows:
Function cur (ele ){
$ (Ele). addClass ("cur"). siblings (). removeClass ("cur ");
}
Function tab (id_tab, tag_tab, id_con, tag_con, act ){
$ (Id_tab). find (tag_tab). eq (0). addClass ("cur ");
$ (Id_con). find (tag_con). eq (0). show (). siblings (tag_con). hide ();
If (! Act) {act = "click "};
If (act = "click "){
$ (Id_tab). find (tag_tab). each (function (I ){
$ (Id_tab). find (tag_tab). eq (I). click (function (){
Cur (this );
$ (Id_con). find (tag_con). eq (I). show (). siblings (tag_con). hide ();
})
})
}
If (act = "mouseover "){
$ (Id_tab). find (tag_tab). each (function (I ){
$ (Id_tab). find (tag_tab). eq (I). mouseover (function (){
Cur (this );
$ (Id_con). find (tag_con). eq (I). show (). siblings (tag_con). hide ();
})
})
}
}
$ (Document). ready (function (){
Tab ("# tri", "li", "# game_con", "div", "click ");
});
DEMO code: after running, you need to refresh to load jquery
<! DOCTYPE html PUBLIC "-// W3C // dtd xhtml 1.0 Transitional // EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <ptml xmlns = "http://www.w3.org/1999/xhtml"> <pead> <meta http-equiv =" content-Type "content =" text/html; charset = gb2312 "/> <title> </title> <link rel =" stylesheet "href =" style/enter.css "type =" text/css "/> <style type = "text/css">. cur {color: red; border-bottom: 2px solid green; background: blue ;}# ngame {width: 500px ;}# tri {width: 500px; background: # f1f1f1; margin: 0; padding: 0; cursor: pointer;} # tri li {float: left; font-size: 12px; padding: 2px; margin-right: 10px; color: #000 ;}# game_con {width: 498px; height: 80px; border: 1px solid # f1f1f1; font-size: 14px ;}# game_con div ul {margin: 0; padding: 0; list-style-type: none; font-size: 14px ;} </style> </pead> <body> <ul id = "tri"> <li> Baidu </li> <li> script home </li> <li> server software </li> </ul> <li> · content baidu.com </li> </ul> content jb51.net content s.jb51.net </body> </ptml>
[Ctrl + A select all Note: If you need to introduce external Js, You need to refresh it to execute]