Implement the switching effect of tab bar in DOM

一个新手
Release: 2017-09-06 13:15:57
Original
1863 people have browsed it

It’s not pretty, but I want to put this js code up and play with it myself.

<style type="text/css">
      .Box {
      width: 240px;
      border: 1px solid #000;
      margin: 100px auto;
      padding: 20px;
    }
Copy after login
.con {
      width: 100%;
      height: 200px;
      background-color: #cccccc;
      border: 1px solid #000;
      margin-top: 10px;
      display: none;
    }
Copy after login
.current {
       background-color: #EEC900;
   }
Copy after login
<p class="Box" id="box">        
<button class="current">one</button>        
<button>two</button>         
<button>three</button>         
<button>four</button>
<p class="con" style="display:block">one</p>         
<p class="con">two</p>         
<p class="con">three</p>        
<p class="con">four</p>
Copy after login
<script>
  var box=document.getElementById("box");
  var btns=box.getElementsByTagName("button");
  var ps=box.getElementsByTagName("p");
  for(var i = 0 ; i<btns.length; i++){
  btns[i].setAttribute("index",i);
  btns[i].onclick=function(){
  for(var j =0 ; j<btns.length ; j++){
  btns[j].removeAttribute("class");
  ps[j].style.display="none";
}
  this.setAttribute("class","current");
  ps[this.getAttribute("index")].style.display="block";
}
}
</script>
Copy after login

The above is the detailed content of Implement the switching effect of tab bar in DOM. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
dom
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!