JS Learning Summary----The classic small case of the tab

Source: Internet
Author: User

<!     DOCTYPE html>body,div,ul,li{margin:0; padding:0; Font-family:arial; Font-size:12px; } UL li{list-Style:none; } #tab {margin:10px auto0;        width:500px;            } #tab ul{position:relative;        top:1px; } #tab li{float: Left;            width:100px;            height:30px; Line-height:30px; Text-Align:center;            border:1px solid #ddd; Margin-right:10px;        Cursor:pointer; } #tab li.select{Border-Bottom:none; Background:-webkit-linear-gradient (top left, #cc0000, #00b3ee, #ffff00);            } #tab div{Display:none;            Clear:both;            height:100px; Line-height:100px; Text-Align:center;        border:1px solid #ddd;        } #tab div.select{Display:block; }    </style>/*tab Ideas: 1, mouse slide to a certain Li above, first let all the Li and div have no select style, then let the current have this select style 2, to manipulate who first get who 3, the development of a functional method to achieve our needs 4, to our Li-bound mouse to move up the event*/        varOtab = document.getElementById (' tab '); varOlis = otab.getelementsbytagname (' li '); varOdivs = otab.getelementsbytagname (' div ')        //nindex is our defined formal parameter, which represents the index of the currently selected element.        functionTabchange (nIndex) { for(vari = 0;i<olis.length;i++) {Olis[i].classname= ""; Odivs[i].classname= ""; } olis[nindex].classname= "Select"; Odivs[nindex].classname= "Select"; }        //after JS loading is complete (for loop also completed), we will manually trigger the onmouseover event, there is a closure problem         for(vari = 0;i<olis.length;i++) {Olis[i].index= I//in each cycle, the index of each li is defined on its own custom attribute indexOlis[i].onmouseover =function() {Tabchange ( This. Index)} }    </script></body>

Simplified version:

JS Learning Summary----The classic small case of the tab

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.