The code is quite concise and easy to understand, so there won’t be much nonsense. Give me the code directly: Copy code The code is as follows: <p> *{ font-size: 14px;margin: 0px;}<br> a{color:#a0b3d6;text-decoration: none;}<br> .tabs{border:1px solid #a0b3d6;margin:100px;width:350px;}<br> .tabs-nav a{background:#eaf0fd; line-height:30px;padding:0px 20px 0px 20px;display:inline-block;border-right:1px solid #a0b3d6;border-bottom:1px solid #a0b3d6; float: left;}<br> .tabs-nav .on{background:white; border-bottom:1px solid white; position:relative;}<br> .tabs-content{display: block; padding:20px;border-top:1px solid #a0b3d6; margin-top:-1px;}<br> .tabs-content_hide{display: none;}<br> <br> </head></p> <body><p> <div class="tabs" id="tabs"><br> <h2 class="tabs-nav clearfix"><br> <a href="javascript:;" class="on">Homepage</a><br> <a href="javascript:;">Technology</a><br> <a href="javascript:;">life</a><br> <a href="javascript:;">Works</a><br> <p class="tabs-content">Homepage</p><br> <p class="tabs-content_hide">Technology</p><br> <p class="tabs-content_hide">Life</p><br> <p class="tabs-content_hide">Works</p><br> <br> </body><br> <footer></footer><br> </html><br> <br><br> <br>------demo.js---------------<br> <br></p> </div> <p></p>Copy code<p></p> <div class="codetitle"><span> The code is as follows:<a style="CURSOR: pointer" data="90492" class="copybut" id="copybut90492" onclick="doCopy('code90492')"><div class="codebody" id="code90492"> <br> window.onload=function(){<br> tabs("tabs","mouseover");<br> }<br> function tabs(id,trigger){<br> var tabBtn = document.getElementById(id).getElementsByTagName("h2")[0].getElementsByTagName("a");<br> var tabsContent = document.getElementById(id).getElementsByTagName("p");<br> for(var i=0;i<tabBtn.length;i ){<br> tabBtn[i].index = i;<br> if(trigger=='mouseover'){<br> tabBtn[i].onmouseover=function(){<br> clearClass();<br> this.className="on";<br> showContent(this.index);<br> }<br> }<br> function showContent(n){<br> for (var i=0; i<tabsContent.length ;i ) {<br> tabsContent[i].index = i;<br> tabsContent[i].className = "tabs-content_hide";<br> }<br> tabsContent[n].className="tabs-content";<br> }<br> function clearClass(){<br> for(var i=0;i<tabBtn.length;i ){<br> tabBtn[i].className="";<br> }<br> }<br> }<br> }<br> </div> <p>是不是很简单就实现了选项卡的切换效果呢,小伙伴们自己美化下就可以用到自己项目中去了。</p></a></span></div>