How to use JavaScript for tab switching

Source: Internet
Author: User

Let's look at the final result of the code implementation:

Using JavaScript to realize the idea is very simple, is to first hide all the content, click on the title corresponding content display,

The CSS code is as follows:

<style type= "Text/css" >
#ltab {
Clear:both;
/ * Clear all floating styles * /
            }
#ltab_1 {
Display:none;
            }
#ltab_2 {
Display:none;
            }     
#ltab_3 {
Display:none;
            }

</style>

HTML content Area:

<body>

/Title Area/

<div class= "Home__tab___4berq" >
<ul>
<li id= "tabc_0" class= "Home__active___1gdd2" onclick= "Changetab (' 0 ')" >
<span class= "Home__tab-text___2p3ej" > Latest news </span><span class= "HOME__LINE___12SRG" ></span>
</li>
<li id= "tabc_1" onclick= "Changetab (' 1 ')" >
<span class= "Home__tab-text___2p3ej" > Cow Dynamics </span><span class= "HOME__LINE___12SRG" ></span>
</li>
<li id= "tabc_2" onclick= "Changetab (' 2 ')" >
<span class= "Home__tab-text___2p3ej" > Warren rank </span><span class= "HOME__LINE___12SRG" ></span>
</li>
<li id= "tabc_3" onclick= "Changetab (' 3 ')" >
<span class= "Home__tab-text___2p3ej" > Master Strategy </span><span class= "HOME__LINE___12SRG" ></span>
</li>
</ul>

</div>

/content Area/

<div id= "Ltab" >

<div id= "Ltab_0" >

The details are too cumbersome to replace with simple text

</div>

<div id= "Ltab_1" >

The details are too cumbersome to replace with simple text

</div>

<div id= "ltab_2">

The details are too cumbersome to replace with simple text

</div>

<div id= "Ltab_3" >

The details are too cumbersome to replace with simple text

</div>

</div>

</body>

The JS code is as follows:

function Changetab (ltab_num) {
For (i = 0; I <= 3; i++) {
document.getElementById ("tabc_" + i). Classname= ""Hide all heading styles
document.getElementById ("ltab_" + i). Style.display = "None";Hide all the layers

   }
document.getElementById ("Tabc_" +ltab_num). Classname= "HOME__ACTIVE___1GDD2" ///class= "HOME__ACTIVE___1GDD2" for the title of the currently selected state
document.getElementById ("ltab_" + ltab_num). Style.display = "block";Show current Layer
 }

Related reference URL:

Http://www.jb51.net/article/74395.htm

How to use JavaScript for tab switching

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.