Javascript實現簡單的選項卡

來源:互聯網
上載者:User

線上示範:http://jsfiddle.net/Web_Code/TbPDd/embedded/result/

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="content-type" content="texthtml;charset=utf-8"><title>TabHost</title><style type="text/css"> #tab li{background-color: #3e3e3e;list-style: none;float: left;margin-left: 2px;color: white;}#tabContent{float: left;display: none;width: 242px;height: 150px;}#tabContent ul{list-style: none;background-color: #ccc;padding-left: 5px;margin-top: 0px;}#main{width: 250px;margin: 0 auto;height: 300px;}</style></head><body><div id="main"><div style="margin-left:-42px"><ul id="tab"><li onclick="javascript:display(1);" style="background-color:#ccc;color:black;">數 據 庫</li><li onclick="javascript:display(2);">前台指令碼</li><li onclick="javascript:display(3);">後台指令碼</li></ul></div><div id="tabContent" style="display:block"><ul><li>MySql</li><li>SQL Server</li><li>Oracle</li><li>DB2</li></ul></div><div id="tabContent"><ul><li>HTML</li><li>Ruby</li><li>JavaScript</li><li>Python</li></ul></div><div id="tabContent"><ul><li>ASP</li><li>PHP</li><li>.Net</li><li>JSP</li></ul></div></div><script type="text/javascript">var divs = document.getElementById("main").getElementsByTagName("div");var lis = document.getElementById("tab").getElementsByTagName("li");function display(num){for(var i = 1; i < divs.length; i++){if(i == num){var con = divs[num];con.style.display="block";lis[i-1].style.backgroundColor = "#ccc";lis[i-1].style.color = "black";}else{divs[i].style.display = "none";lis[i-1].style.color = "white";lis[i-1].style.backgroundColor = "#3e3e3e";}}}</script></body></html>


聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.