JS Native Implementation tab function

Source: Internet
Author: User

Structure:

<div id= "box" > <input type= "button" value= "Books" class= "on" > <input type= "button" value= "Picture" > <input type= "button" value= "column" > <div style= "Display:block;" > Books </div> <div> pictures </div> <div> columns </div></div>

Style:
#box div{            width:200px;            height:200px;            Background: #ccc;            Display:none;        }        . on{            color: #fff;            Background:green;        }

The idea of the tab is that when we click on the current button, we'll clear all the styles and add styles to the current buttons and boxes.

<script>    //Get element    var OBox = document.getElementById ("box");    var abtn = obox.getelementsbytagname ("input");    var adiv = obox.getelementsbytagname ("div");    ABTN is a set of elements, so you need to use the For loop for    (Var i=0;i<abtn.length;i++) {        abtn[i].index=i;        Abtn[i].onclick=function () {            for (var k=0;k<abtn.length;k++) {//First empty all styles                abtn[k].classname = ';                Adiv[k].style.display = ' none ';            }            Add a style to the current button and div            this.classname = ' on ';            Adiv[this.index].style.display = ' block ';        };    } </script>


Relevant knowledge points:

The Index property returns the indexed position of the selected item in the drop-down list
Syntax: Optionobject.index


The ClassName property sets or returns the class property of the element.
Object.classname=classname

























JS Native Implementation tab function

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.