本文實(shí)例講述了JS實(shí)現(xiàn)的簡(jiǎn)單tab切換功能。分享給大家供大家參考,具體如下:
<!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8"> <title>m.survivalescaperooms.com tab切換</title> <style> * { padding: 0; margin: 0 } body { font-size: 12px } ul, li, ol { list-style: none } a { text-decoration: none } .clearfix { clear: both; overflow: hidden } .tab_title ul li { float: left; padding: 0 10px } </style></head><body><div id="Tab1" class="tab clearfix"> <div class="tab_title clearfix"> <ul> <li><a target="_self" href="#" rel="external nofollow" rel="external nofollow" rel="external nofollow" onmouseover="setTab('one',1,3)" id="one1">TAB1</a></li> <li><a target="_self" href="#" rel="external nofollow" rel="external nofollow" rel="external nofollow" onmouseover="setTab('one',2,3)" id="one2">TAB2</a></li> <li><a target="_self" href="#" rel="external nofollow" rel="external nofollow" rel="external nofollow" onmouseover="setTab('one',3,3)" id="one3">TAB3</a></li> </ul> </div> <div class="tab_details clearfix"> <div id="con_one_1" style="display: block;">con_one_1</div> <div style="display: none;" id="con_one_2">con_one_2</div> <div style="display: none;" id="con_one_3">con_one_3</div> </div></div><script type="text/javascript"> //tab切換效果 function setTab(name, cursel, n) { for(var i = 1; i <= n; i++) { var menu = document.getElementById(name + i); var con = document.getElementById("con_" + name + "_" + i); menu.className = i == cursel ? "cur" : ""; con.style.display = i == cursel ? "block" : "none"; } }</script></body></html>運(yùn)行結(jié)果:

感興趣的朋友可以使用本站在線(xiàn)HTML/CSS/JavaScript代碼運(yùn)行工具:http://tools.VeVB.COm/code/HtmlJsRun,測(cè)試上述代碼運(yùn)行效果。
更多關(guān)于JavaScript相關(guān)內(nèi)容感興趣的讀者可查看本站專(zhuān)題:《JavaScript切換特效與技巧總結(jié)》、《JavaScript遍歷算法與技巧總結(jié)》、《JavaScript查找算法技巧總結(jié)》、《JavaScript動(dòng)畫(huà)特效與技巧匯總》、《JavaScript錯(cuò)誤與調(diào)試技巧總結(jié)》、《JavaScript數(shù)據(jù)結(jié)構(gòu)與算法技巧總結(jié)》及《JavaScript數(shù)學(xué)運(yùn)算用法總結(jié)》
希望本文所述對(duì)大家JavaScript程序設(shè)計(jì)有所幫助。
新聞熱點(diǎn)
疑難解答
圖片精選
網(wǎng)友關(guān)注