欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

用HTML标签写常见的注册页面

程序员文章站 2022-04-21 10:50:39
...

在注册页面中使用常见HTML标签

  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>Document</title>
  8. </head>
  9. <body>
  10. <h2>用户注册</h2>
  11. <form action="verify.php" method="post" style="display: grid; gap: 10px">
  12. <!-- 文本框 -->
  13. <div>
  14. <label for="username_id">用户名:</label>
  15. <!-- label标签的for属性与input的id属性对应,点击label后input得到光标 -->
  16. <input
  17. type="text"
  18. name="username"
  19. id="username_id"
  20. value="admin"
  21. placeholder="至少3位"
  22. required
  23. />
  24. </div>
  25. <!-- 密码框 -->
  26. <div>
  27. <!-- required表示不能为空 -->
  28. <label for="password">密码:</label>
  29. <input
  30. type="password"
  31. name="password"
  32. placeholder="至少8位"
  33. id="password"
  34. required
  35. />
  36. <button onclick="showPassword(this,this.form.password)" type="button">
  37. 查看
  38. </button>
  39. </div>
  40. <!-- 邮箱 -->
  41. <div>
  42. <label for="email">邮箱:</label>
  43. <input type="email" name="email" id="email" />
  44. </div>
  45. <!-- 单选按钮 -->
  46. <div>
  47. <!-- name值要一样才会排他,单选按钮不想input一样由用户输入值,所以要设置value属性; checked是默认选择项-->
  48. <label for="secretSex">性别:</label>
  49. <input
  50. type="radio"
  51. name="gender"
  52. id="male"
  53. value="male"
  54. checked
  55. /><label for="male"></label>
  56. <input type="radio" name="gender" id="female" value="female" /><label
  57. for="female"
  58. ></label
  59. >
  60. <input
  61. type="radio"
  62. name="gender"
  63. id="secretSex"
  64. value="secretSex"
  65. /><label for="secretSex">保密</label>
  66. </div>
  67. <div>
  68. <!-- name值需要设置位数组,就是加一对中括号[] -->
  69. <label>爱好:</label>
  70. <input
  71. type="checkbox"
  72. name="hobby[]"
  73. id="game"
  74. value="game"
  75. checked
  76. /><label for="game">游戏</label>
  77. <input
  78. type="checkbox"
  79. name="hobby[]"
  80. id="travel"
  81. value="travel"
  82. /><label for="travel">旅游</label>
  83. <input
  84. type="checkbox"
  85. name="hobby[]"
  86. id="shoot"
  87. value="shoot"
  88. checked
  89. /><label for="shoot">摄影</label>
  90. </div>
  91. <!-- 下拉列表 -->
  92. <div style="width: 300px">
  93. <select name="level" id="" style="width: 100%">
  94. <option value="1">铜牌会员</option>
  95. <option value="2">银牌会员</option>
  96. <option value="3" selected>金牌会员</option>
  97. </select>
  98. </div>
  99. <button>提交</button>
  100. <button type="reset">重置是恢复到默认值</button>
  101. <!-- button标签比较新,不要再用<input type="submit" /> -->
  102. </form>
  103. <h3>复选项做菜单</h3>
  104. <div class="forkmenu">
  105. <label for="menu">菜单</label>
  106. <input type="checkbox" id="menu" />
  107. <ul>
  108. <li><a href="">menu1</a></li>
  109. <li><a href="">menu2</a></li>
  110. <li><a href="">menu3</a></li>
  111. </ul>
  112. <p>菜单项一</p>
  113. <p>菜单项二</p>
  114. <p>菜单项三</p>
  115. </div>
  116. <style>
  117. .forkmenu input[type="checkbox"] {
  118. display: none;
  119. }
  120. .forkmenu input[type="checkbox"]:checked ~ ul ~ p {
  121. display: none;
  122. }
  123. </style>
  124. <script>
  125. function showPassword(btn, ele) {
  126. if (ele.type === "password") {
  127. ele.type = "text";
  128. btn.textContent = "隐藏";
  129. } else {
  130. ele.type = "password";
  131. btn.textContent = "显示";
  132. }
  133. }
  134. </script>
  135. </body>
  136. </html>

用HTML标签写常见的注册页面