jquery点击显示下拉菜单,鼠标经过显示菜单
2个比较简单实用的例子,鼠标经过和点击显示子菜单
js文件
JavaScript Code
- // JavaScript Document
- $(document).ready(function()
- {
- //slides the element with class "menu_body" when paragraph with class "menu_head" is clicked
- $("#firstpane p.menu_head").click(function()
- {
- $(this).css({backgroundImage:"url(down.png)"}).next("div.menu_body").slideToggle(300).siblings("div.menu_body").slideUp("slow");
- $(this).siblings().css({backgroundImage:"url(left.png)"});
- });
- //slides the element with class "menu_body" when mouse is over the paragraph
- $("#secondpane p.menu_head").mouseover(function()
- {
- $(this).css({backgroundImage:"url(down.png)"}).next("div.menu_body").slideDown(500).siblings("div.menu_body").slideUp("slow");
- $(this).siblings().css({backgroundImage:"url(left.png)"});
- });
- });
主要代码
XML/HTML Code
- <div align="center">
- <p><strong> 鼠标点击 </strong></p>
- <div id="firstpane" class="menu_list">
- <p class="menu_head">www.freejs.net</p>
- <div class="menu_body"> <a href="http://www.freejs.net/daohangcaidan.html">导航菜单</a> <a href="#">Link-2</a> <a href="#">Link-3</a> </div>
- <p class="menu_head">Header-2</p>
- <div class="menu_body"> <a href="#">Link-1</a> <a href="#">Link-2</a> <a href="#">Link-3</a> </div>
- <p class="menu_head">Header-3</p>
- <div class="menu_body"> <a href="#">Link-1</a> <a href="#">Link-2</a> <a href="#">Link-3</a> </div>
- </div>
- <!--Code for menu ends here-->
- </div>
- <br />
- <div align="center">
- <!--This is the second division of right-->
- <p><strong> 鼠标经过 </strong></p>
- <div class="menu_list" id="secondpane">
- <!--Code for menu starts here-->
- <p class="menu_head">Header-1</p>
- <div class="menu_body"> <a href="#">Link-1</a> <a href="#">Link-2</a> <a href="#">Link-3</a> </div>
- <p class="menu_head">Header-2</p>
- <div class="menu_body"> <a href="#">Link-1</a> <a href="#">Link-2</a> <a href="#">Link-3</a> </div>
- <p class="menu_head">Header-3</p>
- <div class="menu_body"> <a href="#">Link-1</a> <a href="#">Link-2</a> <a href="#">Link-3</a> </div>
- </div>
- <!--Code for menu ends here-->
- </div>
原文地址:http://www.freejs.net/article_daohangcaidan_25.html