Home > Web Front-end > H5 Tutorial > HTML5 implements Tab switching (through js code)

HTML5 implements Tab switching (through js code)

不言
Release: 2018-08-09 15:09:59
Original
5796 people have browsed it

This article introduces you to the implementation of Tab switching in HTML5 (through js code). It has certain reference value. Friends in need can refer to it. I hope it will be helpful to you.

<!DOCTYPE html>
<html>
<head> <meta charset="utf-8"/>
<title>javascript实现Tab切换</title>
<style>
*{padding:0px;margin:0px;}
ul li {
cursor:pointer;
float:left;
width:100px;
height:30px;
line-height:30px;
text-align:center;
background-color:#fff;
border:1px #bbb solid;
border-bottom:none;
}
ul li.fli {
background-color:#ccc;
color:red;
}
ul {
overflow:hidden;
list-style:none;
}
#tab_con {
width:304px;
height:200px;
}
#tab_con p{
width:304px;
height:200px;
display:none;
border:1px #bbb solid;
border-top:none;
text-align:center;
}
#tab_con p.fp {
display:block;
background-color:#ccc;
}
p:not(#tab_con){
padding:20px 0px;
color:blue;
}
</style>
</head>
<body>
<ul id="tab">
<li class="fli">tab1</li>
<li>tab2</li>
<li>tab3</li>
</ul>
<p id="tab_con">
<p class="fp">这是清华大学的校徽<img src="images/01.jpg"></p>
<p>这是浙江大学的校徽<img src="images/02.jpg"></p>
<p>这是华中科大的校徽<img src="images/03.jpg"></p>
</p>
<script>
var tabs=document.getElementById("tab").getElementsByTagName("li");
var ps=document.getElementById("tab_con").getElementsByTagName("p");
for (var i=0;i<tabs.length;i++) {
tabs[i].onmouseover=function(){
change(this);
}}
function change(obj){
for (var i=0;i<tabs.length;i++){
if(tabs[i]==obj) {
tabs[i].className="fli";
ps[i].className="fp";
}
else {
tabs[i].className="";
ps[i].className=""
} } }
</script>
Copy after login

Recommended related articles:

HTML5 attribute: usage example of margin attribute

Example code of div tag in HTML5

HTML5 attributes: Usage examples of form form attributes

The above is the detailed content of HTML5 implements Tab switching (through js code). For more information, please follow other related articles on the PHP Chinese website!

Related labels:
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