用js写的简单的下拉菜单
<!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="text/html; charset=utf-8" />
<title>无标题文档</title>
<style type="text/css">
*{ margin:0px auto; padding:0px }
#xianshi{
width:130px;
height:30px;
border:1px solid #666;
margin-left:400px;
text-align:center;
vertical-align:middle;
line-height:30px;
position:relative;
z-index:999;}
#xianshi:hover{cursor:pointer}
.xiang{ width:130px;
height:30px;
border:1px solid #666;
text-align:center;
margin-left:400px;
line-height:30px;
vertical-align:middle;
z-index:998;
position:relative;}
.xiang:hover{cursor:pointer;
background-color:#93F}
</style>
</head>
<body>
<div style="width:100%; height:30px; background-color:#F00;margin-top:50px;"></div>
<div style="width:100%; height:30px;">
<div id="xianshi" onclick="xian()">111111111</div>
<div class="xiang" style=" display:none" onclick="huan(this)">111111111</div>
<div class="xiang" style=" display:none" onclick="huan(this)">222222222</div>
<div class="xiang" style=" display:none" onclick="huan(this)">333333333</div>
<div class="xiang" style=" display:none" onclick="huan(this)">444444444</div>
<div class="xiang" style=" display:none" onclick="huan(this)">555555555</div>
<div class="xiang" style=" display:none" onclick="huan(this)">666666666</div>
<div class="xiang" style=" display:none" onclick="huan(this)">777777777</div>
</div>
<div style="width:100%; height:30px; background-color:#F00; z-index:-10; position:relative;"></div>
</body>
<script type="text/javascript">
function xian()
{
var s = document.getElementsByClassName("xiang")
var a = document.getElementById("xianshi")
var nr = a.innerHTML
for(i=0;i<s.length;i++)
{
if(s[i].style.display == "none")
{
s[i].style.display = "block"
if(s[i].innerHTML == nr)
{
s[i].style.display = "none"
} }
else
{
s[i].style.display = "none"
}
}
} function huan(a)
{
var nr = a.innerHTML
document.getElementById("xianshi").innerHTML = nr
var s = document.getElementsByClassName("xiang")
for(i=0;i<s.length;i++)
{
s[i].style.display = "none"
}
}
</script>
</html>
效果如下:


<!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="text/html; charset=utf-8" />
<title>无标题文档</title>
<style type="text/css">
*{ margin:0px auto; padding:0px }
#xianshi{
width:130px;
height:30px;
border:1px solid #666;
margin-left:400px;
text-align:center;
vertical-align:middle;
line-height:30px;
position:relative;
z-index:999;}
#xianshi:hover{cursor:pointer}
.xiang{ width:130px;
height:30px;
border:1px solid #666;
text-align:center;
margin-left:400px;
line-height:30px;
vertical-align:middle;
z-index:998;
position:relative;}
.xiang:hover{cursor:pointer;
background-color:#93F}
</style>
</head>
<body>
<div style="width:100%; height:30px; background-color:#F00;margin-top:50px;"></div>
<div style="width:100%; height:30px;">
<div id="xianshi" onclick="xian()"><img src="1.jpg" height="30px" width="130px" /></div>
<div class="xiang" style=" display:none">222222222</div>
<div class="xiang" style=" display:none">333333333</div>
<div class="xiang" style=" display:none">444444444</div>
<div class="xiang" style=" display:none">555555555</div>
<div class="xiang" style=" display:none">666666666</div>
<div class="xiang" style=" display:none">777777777</div>
</div>
<div style="width:100%; height:30px; background-color:#F00; z-index:-10; position:relative;"></div>
</body>
<script type="text/javascript"> function xian()
{
var s = document.getElementsByClassName("xiang");
var a = document.getElementById("xianshi");
var nr = a.innerHTML; for(i=0;i<s.length;i++)
{
if(s[i].style.display == "none")
{
s[i].style.display = "block";
document.getElementById("xianshi").innerHTML = '<img src="3.jpg" height="30px" width="130px" />';
}
else
{
s[i].style.display = "none";
document.getElementById("xianshi").innerHTML = '<img src="1.jpg" height="30px" width="130px" />';
}
}
}
</script>
</html>


用js写的简单的下拉菜单的更多相关文章
- JQuery -> 超级简单的下拉菜单
使用jquery实现一个超级简单的下拉菜单. 效果图 最初的效果 watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvRmVlTGFuZw==/font/5a6L ...
- 在AJAX里 使用【 XML 】 返回数据类型 实现简单的下拉菜单数据
在AJAX里 使用XML返回数据类型 实现简单的下拉菜单数据 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN ...
- 在AJAX里 使用【 JSON 】 返回数据类型 实现简单的下拉菜单数据
在AJAX里 使用JSON返回数据类型 实现简单的下拉菜单数据 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//E ...
- 仿新浪游戏频道js多栏目全屏下拉菜单导航条
仿新浪游戏频道js多栏目全屏下拉菜单导航条,新浪,游戏频道,js组件,多栏目,全屏下拉,下拉菜单,导航条.代码下载地址:http://www.huiyi8.com/sc/26765.html更多请访问 ...
- 用原生JS实现的一个导航下拉菜单,下拉菜单的宽度与浏览器视口的宽度一样(js+html+css)
这个导航下拉菜单需要实现的功能是:下拉菜单的宽度与浏览器视口的宽度一样宽:一级导航只有两项,当鼠标移到一级导航上的导航项时,相应的二级导航出现.在本案例中通过改变二级导航的高度来实现二级导航的显示和消 ...
- js原生实现三级联动下拉菜单
js代码: <!doctype html> <html> <head> <meta charset="utf-8"> <tit ...
- html简单实现下拉菜单
主要用到的知识ul和li标签 ul li 是一个组合:是无序列表标签,在实际中用的非常多,与之对应的是有序列表:ol lili是不能单独使用,必须在于ul之中的ul是块级元素,能直接定义宽高,而li是 ...
- jquery实现最简单的下拉菜单
<!doctype html> <html> <head> <meta charset="utf-8"> <title> ...
- js 点击按钮显示下拉菜单
<li> <a id = "rank" onclick="showGroup()"></a></li><l ...
随机推荐
- mocha单元测试简易教程
mocha单元测试简易教程 写在前面 其实mocha单元测试的教程网上有很多,也都很简单易懂,但是每个人对同一份的教程也会产生不同的理解,像我这种大概就是走遍了所有弯路才到达终点的人,想通过给大家分享 ...
- 【转】理解Docker容器网络之Linux Network Namespace
原文:理解Docker容器网络之Linux Network Namespace 由于2016年年中调换工作的原因,对容器网络的研究中断过一段时间.随着当前项目对Kubernetes应用的深入,我感觉之 ...
- flask 实现最简单的登录功能
视图函数如下: # Sample.py from flask import Flask, render_template, url_for, request, redirect app = Flask ...
- 【spring源码分析】@Value注解原理
class org.springframework.context.support.PropertySourcesPlaceholderConfigurer 该类实现了的接口:1.org.spring ...
- uboot中工具buildman的用法
1. buildman简介 uboot源码中维护的一款多线程编译测试工具 2. buildman的用法 2.1 进入uboot的源码目录 $ cd <path of uboot> 2.2 ...
- pytorch保证每次运行使用的随机数都相同的方法
其实在代码的开头添加下面几句话即可: # 保证训练时获取的随机数都是一样的 init_seed = torch.manual_seed(init_seed) torch.cuda.manual_see ...
- 012-Shell 提示确认(Y / N,YES / NO)
例1:确认提示(一次) 这个示例代码将为确认提示一次,如果你给输入错误,程序会以状态1退出.这个例子将只接受Y或N或YES或NO(不区分大小写). #!/bin/bash read -r -p &qu ...
- Python - Django - form 组件校验功能
app01/models.py: from django.db import models class UserInfo(models.Model): username = models.CharFi ...
- TIBCO Jaspersoft Studio 报表软件使用教程
Detail 1里面放置动态内容框可以循环遍历数据 版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明.本文链接:https://blog.csdn ...
- idea打开Run Dashboard
在springcloud中,通常会开启多个微服务.单个一个个开就很麻烦 如果没有发现,可以在工程目录下找.idea文件夹下的workspace.xml,在其中增加如下组件 <component ...