tab 栏切换
Posted ximenchuifa
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了tab 栏切换相关的知识,希望对你有一定的参考价值。
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
span {
display: inline-block;
width: 80px;
height: 30px;
background-color: #ccc;
line-height: 30px;
text-align: center;
cursor: pointer;
margin-bottom: 20px;
}
#box div {
display: none;
width: 300px;
height: 100px;
line-height: 100px;
text-align: center;
font-size: 30px;
border: 1px solid #ccc;
}
span.bg {
background-color: red;
color: white;
}
</style>
</head>
<body>
<div id="box">
<!-- /*初始化样式 bg*/ -->
<span class="bg">html</span>
<span>css</span>
<span>
JS
</span>
<div style="display: block;">HTML</div>
<div>CSS</div>
<div>JS</div>
</div>
<script>
var spans = document.querySelectorAll(‘span‘);
var divs = document.querySelectorAll(‘#box div‘);
for (var i = 0; i < spans.length; i++) {
spans[i].index = i;
//点击之后的排他思想
spans[i].onclick = function() {
for (var i = 0; i < spans.length; i++) {
spans[i].className = ‘‘;
divs[i].style.display = ‘none‘;
}
this.className = ‘bg‘;
divs[this.index].style.display = ‘block‘;
}
}
</script>
</body>
</html>
以上是关于tab 栏切换的主要内容,如果未能解决你的问题,请参考以下文章