js和jQuery写简单下拉菜单
1.jQuery写法

<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>下拉菜单</title>
<script type="text/javascript" src="jquery-1.11.2.min.js"></script>
<style type="text/css">
*{ margin:0px; padding:0px;}
#menu{width:100px; height:35px; font-family:'微软雅黑'; background-color:#0C6; text-align:center; font-size:24px; line-height:35px; vertical-align:middle; color:#fff;}
#menu:hover{cursor:pointer;}
.menu1{width:100px; height:35px; font-family:'微软雅黑'; background-color:#FC0; text-align:center; font-size:24px; line-height:35px; vertical-align:middle; color:#fff; list-style:none; }
#menu1{margin:0px; width:100px; padding:0px; display:none;}
.menu1:hover{ cursor:pointer; background-color:#F93}
/*橘子*/
#jz{ position:absolute; left:100px; top:70px; display:none;}
.jz1{ width:100px; height:35px; background-color:#3C3; list-style:none;}
.jz1:hover{ cursor:pointer; background-color:#0F3}
/*香蕉*/
#xj{ position:absolute; left:100px; top:105px; display:none; }
.xj1{ width:100px; height:35px; background-color:#3C3; list-style:none;}
.xj1:hover{ cursor:pointer; background-color:#0F3}
/*苹果*/
#pg{ position:absolute; left:100px; top:35px; display:none; }
.pg1{ width:100px; height:35px; background-color:#3C3; list-style:none;}
.pg1:hover{ cursor:pointer; background-color:#0F3}
</style>
</head> <body>
<div id="menu" class="menu" >菜单</div>
<ul id="menu1">
<li class="menu1">苹果
<ul id="pg" class="pg">
<li class="pg1">淡绿</li>
<li class="pg1">草绿</li>
<li class="pg1">绿色</li>
</ul>
</li>
<li class="menu1">橘子
<ul id="jz" class="jz">
<li class="jz1">橘黄</li>
<li class="jz1">橘红</li>
<li class="jz1">绿色</li>
</ul>
</li>
<li class="menu1">香蕉
<ul id="xj" class="xj">
<li class="xj1">黄色</li>
<li class="xj1">柠檬黄</li>
<li class="xj1">土黄</li>
</ul>
</li>
<li class="menu1">葡萄</li>
<li class="menu1">菠萝</li>
</ul> </body>
<script type="text/jscript">
$(document).ready(function(e) { $("#menu").mouseover(function(e){
$("#menu").css("background-color","#093");
$("#menu1").css("display","block");
}); $("#menu").mouseout(function(e){
$("#menu").css("background-color","#0C6");
$("#menu1").css("display","none");
}); $(".menu1").mouseover(function(e){
$("#menu1").css("display","block");
$(this).children(".jz").css("display","block");
//(this).children(".jz"):this代表是“.menu1”这个选择器,后面的children()代表的是".menu"下面的直接子元素
$(this).children(".xj").css("display","block");
$(this).children(".pg").css("display","block");
}); $(".menu1").mouseout(function(e){
$("#menu1").css("display","none");
$(this).children(".jz").css("display","none");
$(this).children(".xj").css("display","none");
$(this).children(".pg").css("display","none");
}); }); </script>
</html>
2.js写法:

<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<style type="text/css">
#fx
{
width:100px;
height:30px;
background-color:#60F;
color:white;
font-weight:bold;
text-align:center;
line-height:30px;
vertical-align:middle;
}
#fx:hover
{
cursor:pointer;
background-color:#;
}
#menu
{
width:100px;
}
.f
{
width:100px;
height:30px;
background-color:#F06;
color:white;
font-weight:bold;
text-align:center;
line-height:30px;
vertical-align:middle;
}
</style>
</head> <body>
<div id="fx" onmouseover="showlist()" onmouseout="hidelist()">分类</div>
<div id="menu" style="display:none" onmouseover="showlist()" onmouseout="hidelist()">
<div class="f">家电</div>
<div class="f">数码</div>
<div class="f">手机</div>
<div class="f">衣服</div>
</div>
</body>
<script type="text/javascript">
function showlist()
{
document.getElementById("menu").style.display="block";
}
function hidelist()
{
document.getElementById("menu").style.display="none";
}
</script>
</html>
js和jQuery写简单下拉菜单的更多相关文章
- jquery实现多级下拉菜单
支持多种浏览器,体验效果:http://keleyi.com/keleyi/phtml/jqmenu/4.htm 多级菜单,理论上支持无限多的层级,文件结构非常简单的,以下是完整代码: <!DO ...
- 仿新浪游戏频道js多栏目全屏下拉菜单导航条
仿新浪游戏频道js多栏目全屏下拉菜单导航条,新浪,游戏频道,js组件,多栏目,全屏下拉,下拉菜单,导航条.代码下载地址:http://www.huiyi8.com/sc/26765.html更多请访问 ...
- jQuery+Superfish制作下拉菜单
superfish制作下拉菜单真的很方便而好很好用,而且还可以通过Superfish提供的参数来控制下拉菜单的不同效果,而且他没有层级限制,换句话说可以通过Superfish来写你想要的层级菜单. 官 ...
- CSS写动态下拉菜单 -----2017-03-27
动态网站第一步:动态下拉菜单 关键点: overflow:hidden max-height xx:hover {} 设置当鼠标移上之后的效果 transition: 设置过度时间 cursor: ...
- JQuery设置获取下拉菜单选项的值 多实例
分享下JQuery如何设置获取下拉菜单某个选项的值,多种方法,值得收藏. JQuery获取和设置Select选项 获取Select :获取select 选中的 text :$(“#ddlRegType ...
- 基于jquery网站左侧下拉菜单
网站左侧下拉菜单jQuery代码.这是一款蓝色风格的适合做后台下拉菜单代码.效果图如下: 在线预览 源码下载 实现的代码: <div class="container"& ...
- 用原生JS实现的一个导航下拉菜单,下拉菜单的宽度与浏览器视口的宽度一样(js+html+css)
这个导航下拉菜单需要实现的功能是:下拉菜单的宽度与浏览器视口的宽度一样宽:一级导航只有两项,当鼠标移到一级导航上的导航项时,相应的二级导航出现.在本案例中通过改变二级导航的高度来实现二级导航的显示和消 ...
- jquery 只有二级下拉菜单
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
- jQuery cxSelect 联动下拉菜单
插件简介 cxSelect 是基于 jQuery 的多级联动菜单插件,适用于省市.商品分类等联动菜单. 列表数据通过 AJAX 获取,也可以自定义,数据内容使用 JSON 格式. 同时兼容 Zepto ...
随机推荐
- android-SQLite 和 Content
SQLite 游标(Cursor)相当于指向底层数据中结果集的指针,而不是提取和返回结果值的副本,是在结果集中对位置(行)进行控制的管理方式. moveToFirst:把游标移动到查询结果的第一行 m ...
- 航道水下地形DEM构建方法比较
论文<航道水下数字高程模型的构建方法> 对航道水下地形建立DEM,技术路线:先构建TIN,手动去除多余三角边,再利用CAD ObjectARX二次开发接口中提供的几种内插方法生成grid ...
- C#实现 ffmpeg视频转码、播放
近来公司项目要求实现全景相机的视频截取,但是截取的视频需求转码上传.经过研究采用ffmpeg转码,奉上一个详细介绍的博文: 最简单的基于FFMPEG的转码程序 主要是转码的操作过程,能够实现了从相机获 ...
- Juicy Couture_百度百科
Juicy Couture_百度百科 Juicy Couture
- c# 获取全屏 中鼠标焦点的位置坐标
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.D ...
- 一个关于Integer的秘密
先让大家看一段简单的代码: public static voidmain(String[] args) { Integera = 1; Integerb = 1; Integerc = 222; In ...
- POJ3771+Prim
最小生成树的应用 数据量小. /* Prim */ #include<stdio.h> #include<string.h> #include<stdlib.h> ...
- Swift和Objective-C混合编程
假设你现在就是一个iOS程序员,你对Objective-C很熟悉,对iOS开发也很熟悉,然而,苹果公司在iOS 8之后推出了Swift语言.那么,如何才能快速地从Objective-C过渡到Swift ...
- 如何解决Android 5.0中出现的警告:Service Intent must be explicit
有些时候我们使用Service的时需要采用隐私启动的方式,但是Android 5.0一出来后,其中有个特性就是Service Intent must be explitict,也就是说从Lollip ...
- 简单天气应用开发——解析HeWeather JSON
借助和风天气API成功获取到了我想要的天气信息,但在怎么提取出我想要的数据上又遇到了问题. {"HeWeather data service 3.0":[{"basic& ...