亚洲国产日韩欧美一区二区三区,精品亚洲国产成人av在线,国产99视频精品免视看7,99国产精品久久久久久久成人热,欧美日韩亚洲国产综合乱

搜索
博主信息
博文 11
粉絲 0
評論 0
訪問量 9795
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板
表單初體驗
向日葵
原創(chuàng)
535人瀏覽過

用html實現(xiàn)一個簡單的用戶注冊界面,并實現(xiàn)密碼的查看與隱藏

我們要用到的html標簽有:form,他的屬性有兩個比較重要——method(指定表單的提交方式,get或post),action(指定表單提交的后端處理文件,如:register.php);label+input,一對標簽可以實現(xiàn)綁定,其中input有很多類型,如:text文本類型、password密碼類型、email郵箱類型、checkbox多選框、radio單選框,還有一種特殊的表單:select下拉菜單;
那我們用上面的input類型,能形成一個什么樣的用戶注冊頁面呢,如下圖所示:

那么實現(xiàn)界面上這些功能的代碼如下:

  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. <body>
  10. <!-- 用戶名、密碼、性別、愛好、郵箱、下拉列表 -->
  11. <form action="register.php" method="post" style="display: grid; gap: 10px;">
  12. <div>
  13. <label for="username">用戶名:</label>
  14. <input
  15. type="text"
  16. name="username"
  17. id="username"
  18. required
  19. value="admin"
  20. placeholder="英文6-8位"
  21. />
  22. </div>
  23. <div>
  24. <label for="password">密碼:</label>
  25. <input
  26. type="password"
  27. name="password"
  28. id="password"
  29. required
  30. placeholder="英文+數字6-12位"
  31. />
  32. <button onclick="showPassword(this,this.form.password)" type="button">
  33. 顯示
  34. </button>
  35. </div>
  36. <div>
  37. <label for="email">郵箱:</label>
  38. <input type="email" name="email" id="email" placeholder="請輸入郵箱" />
  39. </div>
  40. <div>
  41. <label for="secret">性別:</label>
  42. <input type="radio" name="gender" id="male" value="male" />
  43. <label for="male"></label>
  44. <input type="radio" name="gender" id="female" value="female" />
  45. <label for="female"></label>
  46. <input type="radio" name="gender" id="secret" value="secret" checked />
  47. <label for="secret">保密</label>
  48. </div>
  49. <div>
  50. <label>愛好:</label>
  51. <input type="checkbox" name="hobby[]" id="football" value="football" />
  52. <label for="football">足球</label>
  53. <input
  54. type="checkbox"
  55. name="hobby[]"
  56. id="basketball"
  57. value="basketball"
  58. />
  59. <label for="basketball">藍球</label>
  60. <input
  61. type="checkbox"
  62. name="hobby[]"
  63. id="pingpangball"
  64. value="pingpangball"
  65. />
  66. <label for="pingpangball">乒乓球</label>
  67. <input
  68. type="checkbox"
  69. name="hobby[]"
  70. id="music"
  71. value="music"
  72. checked
  73. />
  74. <label for="music">音樂</label>
  75. </div>
  76. <label for="identity">用戶身份:</label>
  77. <select name="level" id="identity">
  78. <option value="1" checked>普通會員</option>
  79. <option value="2">高級會員</option>
  80. <option value="3">永久會員</option>
  81. </select>
  82. <div>
  83. <button type="submit">提交</button>
  84. <button type="reset">重置</button>
  85. </div>
  86. </form>
  87. <script>
  88. function showPassword(btn, ele) {
  89. if (ele.type === 'password') {
  90. ele.type = 'text'
  91. btn.textContent = '隱藏'
  92. } else {
  93. ele.type = 'password'
  94. btn.textContent = '顯示'
  95. }
  96. }
  97. </script>
  98. </body>
  99. </html>

這樣一個雖然丑但是有趣實用的注冊就完成啦~

批改老師:PHPzPHPz

批改狀態(tài):合格

老師批語:用列表會更加美觀,方便后續(xù)復習
本博文版權歸博主所有,轉載請注明地址!如有侵權、違法,請聯(lián)系admin@php.cn舉報處理!
全部評論 文明上網理性發(fā)言,請遵守新聞評論服務協(xié)議
0條評論
作者最新博文
關于我們 免責申明 意見反饋 講師合作 廣告合作 最新更新
php中文網:公益在線php培訓,幫助PHP學習者快速成長!
關注服務號 技術交流群
PHP中文網訂閱號
每天精選資源文章推送
PHP中文網APP
隨時隨地碎片化學習
PHP中文網抖音號
發(fā)現(xiàn)有趣的

Copyright 2014-2025 http://ipnx.cn/ All Rights Reserved | php.cn | 湘ICP備2023035733號

  • 登錄PHP中文網,和優(yōu)秀的人一起學習!
    全站2000+教程免費學