当前位置:   article > 正文

h5实现下拉选择_h5下拉框

h5下拉框

一、先看效果图 

 

 

二、简单实现一下代码

首先你要引入jQuery.js文件

  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta http-equiv="X-UA-Compatible" content="IE=edge">
  6. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  7. <title>下拉菜单</title>
  8. </head>
  9. <style>
  10. * {
  11. margin: 0;
  12. padding: 0;
  13. text-decoration: none;
  14. list-style: none;
  15. }
  16. .downorder {
  17. width: 88px;
  18. height: 32px;
  19. font-size: 14px;
  20. border: 1px solid #eee;
  21. border-radius: 4px;
  22. position: relative;
  23. margin: 100px;
  24. }
  25. .order {
  26. height: 100%;
  27. color: #666;
  28. display: flex;
  29. justify-content: left;
  30. align-items: center;
  31. padding-left: 10px;
  32. }
  33. .order::after {
  34. content: '';
  35. width: 20px;
  36. height: 20px;
  37. position: absolute;
  38. right: 5px;
  39. display: inline-block;
  40. background: url(../../img/select1.png) no-repeat center/100% 100%;
  41. }
  42. .downtext {
  43. border-radius: 4px;
  44. overflow: hidden;
  45. border: 1px solid #eee;
  46. background-color: #fff;
  47. position: absolute;
  48. top: 32px;
  49. left: 0;
  50. z-index: 10;
  51. /* display: none; */
  52. }
  53. .downtext a {
  54. width: 100%;
  55. height: 32px;
  56. display: inline-block;
  57. font-size: 14px;
  58. line-height: 30px;
  59. text-align: center;
  60. color: #666;
  61. }
  62. </style>
  63. <body>
  64. <!--下拉菜单-->
  65. <div class="downorder">
  66. <p class="order">
  67. 下拉菜单
  68. </p>
  69. <div class="downtext">
  70. <a href="#">text1</a>
  71. <a href="#">text2</a>
  72. <a href="#">text3</a>
  73. <a href="#">text4</a>
  74. </div>
  75. </div>
  76. <script src="../../js/jquery-3.2.1.min.js"></script>
  77. <script>
  78. // 下拉菜单
  79. $(function () {
  80. $(".downtext").hide();
  81. $(".order").click(function () {
  82. $(".downtext").slideToggle();
  83. })
  84. $(".downtext a").click(function () {
  85. var index = $('.downtext a').index(this);
  86. var a = document.querySelectorAll(".downtext a");
  87. $(".order").text(a[index].innerHTML);
  88. $(".downtext").hide();
  89. })
  90. })
  91. </script>
  92. </body>
  93. </html>

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/小丑西瓜9/article/detail/254001
推荐阅读
相关标签
  

闽ICP备14008679号