jquery simple few lines of code show tab switch

Source: Internet
Author: User

HTML code:

<div class= "Ry_jj_tab" >
<div class= "Tab_box" >
<a href= "#tab1" class= "selected" onclick= "Js_method (); return false;" > Basic Information </a>
<a href= "#tab2" onclick= "Js_method (); return false;" > Honor and Evaluation </a>
<a href= "#tab3" onclick= "Js_method (); return false;" > Representative Performance </a>
<a href= "#tab4" onclick= "Js_method (); return false;" > Social Activities </a>
<a href= "#tab5" onclick= "Js_method (); return false;" > Major Publications </a> </div>
<div class= "Tab_main tab_main1" id= "Tab1" > <!--<span class= "XX" ></span>--

<div class= "Tab_main_box" > {dede:field.jibenxinxi/} </div>
</div>
<div class= "Tab_main tab_main1" id= "tab2" style= "Display:none;" > <span class= "xx" ></span>
<div class= "Tab_main_box" > {dede:field.rongyu/} </div>
</div>
<div class= "Tab_main tab_main1" id= "Tab3" style= "Display:none;" > <span class= "xx" ></span>
<div class= "Tab_main_box" > {dede:field.yeji/} </div>
</div>
<div class= "Tab_main tab_main1" id= "Tab4" style= "Display:none;" > <span class= "xx" ></span>
<div class= "Tab_main_box" > {dede:field.shehuihuodong/} </div>
</div>
<div class= "Tab_main tab_main1" id= "Tab5" style= "Display:none;" > <span class= "xx" ></span>
<div class= "Tab_main_box" > {dede:field.zhushu/} </div>
</div>
</div>

Here is the JS code

<script>
$ (document). Ready (function () {

$ (function () {
$ (". Tab_box > A"). On ("click", Function () {//give. Tab_box > A This object to bind a fixed-point click event
var index = $ (this). index ();//Gets the indexed value of the clicked object to the variable in index
$ (this). AddClass ("selected"). Siblings (). Removeclass ("selected");//Click on object highlighting, sibling node Delete highlight
$ (". Tab_main1"). EQ (index). CSS ("Display", "block"). Siblings (". Tab_main1"). CSS ("display", "none");//Want to display the clicked content, Other non-node content hiding
})
})

})
</script>

PS: Never understood $ (this) the variable is what it is, and today we finally realize that this is the object of the current event, index () indexed value, $ (this). Index () Click on the indexed value of the object.

jquery simple few lines of code show tab switch

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.