JavaScript Object-oriented series 4--instance (simplest object-oriented tab)

Source: Internet
Author: User

"Feature description"

Click on the three buttons to display the respective tabs

"HTML code description"

<div class= "box" id= "box" >    <ul class= "list" >        <li class= "in_active" > First tab </li>        <li class= "in" > second tab </li>        <li class= "in" > Third tab </li>    </ul>    < Nav class= "Conlist" >        <a class= "con_active" href= "javascript:;" > First control button </a>        <a class= "Con" href= "javascript:;" > Second control button </a>        <a class= "Con" href= "javascript:;" > Third control button </a>    </nav>    </div>

"CSS Key code description"

/*in tab normal state, default does not show*/.inch,. in_active{Display:none;    width:600px;    height:100px;    Background:orange; Font-size:50px; Line-height:100px; Text-Align:center;}/*In_active is selected for the tab and appears after selection*/. in_active{Display:block;}/*Con is the normal state of the button, the default text color is black*/. con,.con_active{Color:black; Background-Color:orange;}/*con_active the button is selected, the text color is white when selected*/. con_active{Color:white; }

"JS Code description"

functionTab (obj) {/*element gets*/    //get tab Show Section     This. olist = Obj.getelementsbytagname (' ul ') [0];  This. AIn = This. Olist.getelementsbytagname (' Li '); //get tab Control Section     This. oconlist = obj.getelementsbytagname (' nav ') [0];  This. ACon = This. Oconlist.getelementsbytagname (' a '); /*Variable Settings*/    //Tab Count     This. Count = This. Ain.length; //current Number of pages     This. Cur = 0; var_this = This;  for(vari = 0; I < This. Count; i++){        //Set Index         This. Acon[i].index =i; //add an event to a button         This. Acon[i].onclick =function() {_this.cur= This. Index; _this.Switch(); }}}tab.prototype.Switch=function(){    //Remove All     for(vari = 0; I < This. Count; i++){         This. Ain[i].classname = ' in ';  This. acon[i].classname = ' con '; }    //Displays the current     This. ain[ This. Cur].classname = ' in_active ';  This. acon[ This. Cur].classname = ' con_active '; }//get tab ElementvarOBox = document.getElementById (' box ');//Constructing Tab ObjectsvarTAB1 =NewTab (OBox);

"Effect Show"

"Source View"

JavaScript Object-oriented series 4--instance (simplest object-oriented tab)

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.