JavaScript如何制作下拉菜单


当前第2页 返回上一页

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

69

70

71

72

73

74

75

76

77

78

79

80

<!DOCTYPE html>

<html>

<head>

  <meta charset="UTF-8">

  <meta name="viewport" content="width=device-width, initial-scale=1.0">

  <title>W3Cschool(w3cschool.cn)</title>

  <style>

    * {

      margin: 0;

      padding: 0;

    }

    li {

      list-style-type: none;

    }

    a {

      text-decoration: none;

      font-size: 14px;

    }

    .nav {

      margin: 100px;

    }

    .nav>li {

      position: relative;

      float: left;

      width: 80px;

      height: 41px;

      text-align: center;

    }

    .nav li a {

      display: block;

      width: 100%;

      height: 100%;

      line-height: 41px;

      color: #333;

    }

    .nav>li>a:hover {

      background-color: #eee;

    }

    .nav ul {

      display: none;

      position: absolute;

      top: 41px;

      left: 0;

      width: 100%;

      border-left: 1px solid #FECC5B;

      border-right: 1px solid #FECC5B;

    }

    .nav ul li {

      border-bottom: 1px solid #FECC5B;

    }

    .nav ul li a:hover {

      background-color: #FFF5DA;

    }

  </style>

</head>

<body>

  <ul>

    <li>

      <a href="javascript:;">下拉</a>

      <ul>

        <li><a href="javascript:;">下拉1</a></li>

        <li><a href="javascript:;">下拉2</a></li>

        <li><a href="javascript:;">下拉3</a></li>

        <li><a href="javascript:;">下拉4</a></li>

      </ul>

    </li>

  </ul>

  <script>

    var lis = document.querySelector('.nav').children;

    for (var i = 0; i < lis.length; i++) {

      lis[i].onmouseover = function () {

        this.children[i].style.display = 'block';

      }

      lis[i].onmouseout = function () {

        this.children[i].style.display = 'none';

      }

    }

  </script>

</body>

</html>

推荐学习:《javascript高级教程

以上就是JavaScript如何制作下拉菜单的详细内容,更多文章请关注木庄网络博客

返回前面的内容

相关阅读 >>

实例详解javascript中split字符串分割函数

javascript如何查询数组长度

javascript中return的含义是什么

使用javascript的模块加载器

详解es6中的for … of循环和可迭代对象

javascript今年25 岁了!

详解javascript降低函数复杂度的方法

学习javascript里的dom知识

鲜为人知的 json.stringify 用法

javascript阻塞问题

更多相关阅读请进入《javascript》频道 >>




打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...