Use the Juery web page tab to implement code

Source: Internet
Author: User

First, the front-end code
Copy codeThe Code is as follows:
<Div class = "tab">
<Div class = "tab_menu">
<Ul>
<Li class = "selected"> Personal Information </li>
<Li class = "selected"> my photos </li>
<Li class = "selected"> my blog </li>
<Div class = "clear"> </div>
</Ul>
</Div>
<Div class = "tab_box">
<Div class = "box"> My QQ: 1511109272 </div>
<Div class = "box hide"> hi </div>
<Div class = "box hide"> hello <br> </div>
</Div>
</Div>

Then you can set the jquery code.
Copy codeThe Code is as follows:
$ (Function (){
// Switch the webpage Tab
Var $ menu_li = $ ("div. tab_menu ul li ");
$ Menu_li.click (function (){
$ (This). addClass ("selected") // The current <li> highlight
. Siblings (). removeClass ("selected"); // remove the highlight of other peers <li>
Var index = $ menu_li.index ($ (this); // locate the index of the <li> subnode
$ ("Div. tab_box> div") // The DIV whose index is N is displayed.
. Eq (index). show ()
. Siblings (). hide ();
})
})

You can set the CCS style.
Copy codeThe Code is as follows:
. Clear {clear: both; height: 0px; overflow: hidden ;}
. Tab {width: 400px; font-size: 12px ;}
. Tab_menu ul {padding: 0px; margin: 0px ;}
. Tab_menu li {list-style: none; display: block; float: left;
Background: # C2CEFE; height: 22px; line-height: 22px;
Padding: 0px 8px; margin-right: 6px; border: # 86B4CA 1px solid;
}
. Box {width: 400px; height: 200px; overflow: hidden; border: # A8C9D9 1px solid; padding: 10px 8px ;}
. Tab_menu ul li. selected {background: # dadada; cursor: pointer ;}
. Hide {display: none ;}

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.