js代碼實現下拉式功能表

來源:互聯網
上載者:User

標籤:png   ack   分享   nav   his   經典   asc   首頁   中心   

效果

 

js代碼:

<script type="text/javascript">
function ShowSub(li) {//函數定義
var subMenu = li.getElementsByTagName("ul")[0] ;//擷取
subMenu.style.display = " block ";
}

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

</script>

 

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;}//ie7顯示寬度的相容性  設定width  而不用padding的自適應
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;}

 html代碼

<div id="nav">

<ul>
<li><a href="#">首頁</a></li>
<li onmouseover="ShowSub(this)" onmouseout="HideSub(this)" ><a href="#">課程大廳</a>
<ul>
<li><a href="#">JavaScript</a></li>
<li><a href="#">Html/CSS</a></li>
</ul>
</li>
<li onmouseover="ShowSub(this)" onmouseout="HideSub(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>

js代碼實現下拉式功能表

聯繫我們

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