<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>tab切换</title>
</head>
<body>
<div id="tab1" style="width: 50%;height: 200px;background-color: red;float: left;">我是tab1</div>
<div id="tab2" style="width: 50%;height: 200px;background-color: pink;display: inline-block;;">我是tab2</div>
<div id="data1" style="width: 100%;height: 200px;">点击tab1显示我</div>
<div id="data2" style="width: 100%;height: 200px;">点击tab2显示我</div>
<script>
let tab1=document.getElementById("tab1")
let tab2=document.getElementById("tab2")
let data1=document.getElementById("data1")
let data2=document.getElementById("data2")
tab2.addEventListener("click",function(){
data1.style.display="none";
data2.style.display="block"
})
tab1.addEventListener("click",function(){
data1.style.display="block";
data2.style.display="none"
})
</script>
</body>
</html>
标签:style,效果,tab2,tab1,切换,tab,document,data1,data2 From: https://blog.51cto.com/u_15460007/7330788运行结果