zoukankan      html  css  js  c++  java
  • javascript实现下拉菜单的显示与隐藏

    demo.html

    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>实现下拉菜单效果</title>
        <link rel="stylesheet" type="text/css" href="demo.css">
        <script type="text/javascript" src="demo.js"></script>
    </head>
    <body>
    <div id="nav">
        <ul>
            <li><a href="#">首页</a></li>
            <li onmouseover="displaySubMenu(this)" onmouseout="hideSubMenu(this)"><a href="#">课程大厅</a>
                <ul>
                    <li><a href="#">JavaScript</a></li>
                    <li><a href="#">Html/CSS</a></li>
                </ul>
            </li>
            <li onmouseover="displaySubMenu(this)" onmouseout="hideSubMenu(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>
    </body>
    </html>
    

      demo.js

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

      demo.css

    *{ margin:0px; padding:0px;}
    body{ font-family:Verdana, Geneva, sans-serif; font-size:14px;}
    #nav{ 600px; height:40px; background-color:#eee; margin:0 auto;}
    ul{ list-style:none;}
    ul li{ float:left; line-height:40px; text-align:center; 100px;}
    
    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;}
    

      效果:

    2017-09-0 6   2017-09-06   

  • 相关阅读:
    发布spring cloud + vue项目
    以太坊上发行ERC20代币
    [转]大白话讲解Promise(一)
    比特币测试网络搭建
    非对称加密, 助记词, PIN, WIF
    搭建EOS未完
    [转]EOS智能合约 & 私链激活 & 基本操作
    [转]https://www.jianshu.com/p/06443248f4d8
    web3js 进行转账
    [转]How to Send Ethereum with Web3.js and Node
  • 原文地址:https://www.cnblogs.com/guangzhou11/p/7484235.html
Copyright © 2011-2022 走看看