<!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写的简单的下拉菜单的更多相关文章

  1. JQuery -&gt; 超级简单的下拉菜单

    使用jquery实现一个超级简单的下拉菜单. 效果图 最初的效果 watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvRmVlTGFuZw==/font/5a6L ...

  2. 在AJAX里 使用【 XML 】 返回数据类型 实现简单的下拉菜单数据

    在AJAX里 使用XML返回数据类型 实现简单的下拉菜单数据 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN ...

  3. 在AJAX里 使用【 JSON 】 返回数据类型 实现简单的下拉菜单数据

    在AJAX里 使用JSON返回数据类型 实现简单的下拉菜单数据 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//E ...

  4. 仿新浪游戏频道js多栏目全屏下拉菜单导航条

    仿新浪游戏频道js多栏目全屏下拉菜单导航条,新浪,游戏频道,js组件,多栏目,全屏下拉,下拉菜单,导航条.代码下载地址:http://www.huiyi8.com/sc/26765.html更多请访问 ...

  5. 用原生JS实现的一个导航下拉菜单,下拉菜单的宽度与浏览器视口的宽度一样(js+html+css)

    这个导航下拉菜单需要实现的功能是:下拉菜单的宽度与浏览器视口的宽度一样宽:一级导航只有两项,当鼠标移到一级导航上的导航项时,相应的二级导航出现.在本案例中通过改变二级导航的高度来实现二级导航的显示和消 ...

  6. js原生实现三级联动下拉菜单

    js代码: <!doctype html> <html> <head> <meta charset="utf-8"> <tit ...

  7. html简单实现下拉菜单

    主要用到的知识ul和li标签 ul li 是一个组合:是无序列表标签,在实际中用的非常多,与之对应的是有序列表:ol lili是不能单独使用,必须在于ul之中的ul是块级元素,能直接定义宽高,而li是 ...

  8. jquery实现最简单的下拉菜单

    <!doctype html> <html> <head> <meta charset="utf-8"> <title> ...

  9. js 点击按钮显示下拉菜单

    <li> <a id = "rank" onclick="showGroup()"></a></li><l ...

随机推荐

  1. 团队作业-Beta冲刺(4/4)

    队名:软工9组 组长博客:https://www.cnblogs.com/cmlei/ 作业博客:https://edu.cnblogs.com/campus/fzu/SoftwareEngineer ...

  2. Alpha3

    队名:福大帮 组长博客链接:https://www.cnblogs.com/mhq-mhq/p/11899921.html 作业博客 :https://edu.cnblogs.com/campus/f ...

  3. docker 安装redis cluster集群

    安装Redis镜像 docker pull yyyyttttwwww/redis 创建redis容器 docker run -it -d --name r1 -p 5001:6379 --net=ne ...

  4. tomcat请求响应代码分享

    NioEndpoint的Poller轮询器持续进行扫描是否有新的event()方法调用后产生新的event配置. 发现后执行AbstractProtocol.class中的process()方法进行处 ...

  5. vue-vuex的使用

    做后台项目的时候,有时候会需要用到状态管理,VUEX就能够很好的为我们解决好这个问题. 安装 VUEX npm install vuex --save 具体使用: 建立 src/store/index ...

  6. MySQL count

    https://www.jianshu.com/p/1b0a1f641e80] 不同引擎count(*)实现方式不同 MyISAM引擎把一个表的总行数记录在了磁盘上,执行count(*)会直接返回这个 ...

  7. SpringBoot项目实现配置实时刷新功能

    需求描述:在SpringBoot项目中,一般业务配置都是写死在配置文件中的,如果某个业务配置想修改,就得重启项目.这在生产环境是不被允许的,这就需要通过技术手段做到配置变更后即使生效.下面就来看一下怎 ...

  8. SUSE操作系统,如何查看操作系统版本?

    背景描述: 今天需要统计操作系统版本,我在其中一台主机上执行cat /etc/redhat-release发现没有这个,应该知道不是redhat系统,然后想,怎么查来着,忘了,找了下,再此记录下. # ...

  9. 调用百度API接口 正解析地址和逆解析

    地址解析(结构化地址 解析得到 经纬度): public void SaveLocation(DataRequest<Location> request, DataResponse< ...

  10. Delphi ADOConnection连接

    unit Unit_DM; interface usesSysUtils, Classes, DB, ADODB,inifiles,windows,forms,controls; typeTDM = ...