javascript實現下拉式功能表的顯示與隱藏

來源:互聯網
上載者:User

標籤:首頁   elements   family   eva   pre   dem   meta   ul li   ack   

demo.html

<!DOCTYPE html><html lang="en"><head>    <meta charset="UTF-8">    <title>實現下拉式功能表效果</title>    <link rel="stylesheet" type="text/css" href="demo.css">    <script type="text/javascript" src="demo.js"></script></head><body><div id="nav">    <ul>        <li><a href="#">首頁</a></li>        <li onmouseover="displaySubMenu(this)" onmouseout="hideSubMenu(this)"><a href="#">課程大廳</a>            <ul>                <li><a href="#">JavaScript</a></li>                <li><a href="#">Html/CSS</a></li>            </ul>        </li>        <li onmouseover="displaySubMenu(this)" onmouseout="hideSubMenu(this)"><a href="#">學習中心</a>            <ul>                <li><a href="#">視頻學習</a></li>                <li><a href="#">執行個體練習</a></li>                <li><a href="#">問答</a></li>            </ul>        </li>        <li><a href="#">經典案例</a></li>        <li><a href="#">關於我們</a></li>    </ul></div></body></html>

  demo.js

function displaySubMenu(li) {    var subMenu = li.getElementsByTagName("ul")[0];    subMenu.style.display = "block";}function hideSubMenu(li) {    var subMenu = li.getElementsByTagName("ul")[0];    subMenu.style.display = "none";}

  demo.css

*{ margin:0px; padding:0px;}body{ font-family:Verdana, Geneva, sans-serif; font-size:14px;}#nav{ width:600px; height:40px; background-color:#eee; margin:0 auto;}ul{ list-style:none;}ul li{ float:left; line-height:40px; text-align:center; width:100px;}a{ text-decoration:none; color:#000; display:block;}a:hover{ color:#F00; background-color:#666;}ul li ul li{ float:none;background-color:#eee; margin:2px 0px;}ul li ul{ display:none;}

  效果:

 

2017-09-0 6   2017-09-06   

javascript實現下拉式功能表的顯示與隱藏

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.