This article describes the principle and effect implementation of JavaScript's tab switching principle and method. Share it for your reference.
The specific implementation method is as follows:
Copy the code as follows: <html>
<head>
<style type="text/css">
#container{border:solid 1px green;width:300px;height:300px;}
li{float:left;margin-left:20px;}
p{float:left;}
#sports,#military,#bbs{display:none;}
</style>
<script type="text/javascript">
function tab(pid){
var ps = ['news','sports','military','bbs'];
for(var i=0,len=ps.length;i<len;i++){
if(ps[i] == pid){
document.getElementById(ps[i]).style.display = "block";
}else{
document.getElementById(ps[i]).style.display = "none";
}
}
}
</script>
</head>
<body>
<div id="container">
<ul>
<li onmouseover="tab('news');">News</li>
<li onmouseover="tab('sports');">Sports</li>
<li onmouseover="tab('military');">Military</li>
<li onmouseover="tab('bbs');">Forum</li>
</ul>
<p id="news">News NewsNews News</p>
<p id="sports">Sports Sports Sports Sports</p>
<p id="military">Military Military Military Military</p>
<p id="bbs">Forum Forum Forum Forum Forum</p>
</div>
</body>
</html>
I hope this article will be helpful to everyone's JavaScript programming.