经验首页 前端设计 程序设计 Java相关 移动开发 数据库/运维 软件/图像 大数据/云计算 其他经验
当前位置:技术经验 » HTML/CSS » HTML5 » 查看文章
HTML 5 详解之表单的初级验证
来源:cnblogs  作者:Hateyes  时间:2021/2/18 15:31:31  对本文有异议
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <title>表单的初级验证</title>
  6. </head>
  7. <body>
  8.  
  9. <h1>注册</h1>
  10.  
  11. <!--
  12. 表单:
  13. action:表单提交的位置,可以是网站,也可以是一个请求处理地址
  14. method:get/post 表单的两种提交方式,为确保数据安全常用 post 方式提交
  15. get 方式提交:我们可以在 url 中看到我们提交的信息,不安全,高效
  16. post 方式提交:比较安全,可传输大文件
  17. -->
  18. <form action="1.我的第一个网页.html" method="get">
  19.  
  20. <!--
  21. 文本输入框:
  22. type:text
  23. value="狂神好帅":默认初始值
  24. maxlength="8":最长能写几个字符
  25. size="30":文本框长度
  26. placeholder:提示信息
  27. required:判空
  28. <input type="text" name="username">
  29. -->
  30. <p>名字:<input type="text" name="username" placeholder="请输入用户名" required/> </p>
  31.  
  32. <!--
  33. 密码框:
  34. type:password
  35. placeholder:提示信息
  36. required:判空
  37. <input type="password" name="pwd">
  38. -->
  39. <p>密码:<input type="password" name="pwd" placeholder="请输入密码" required/> </p>
  40.  
  41. <!--
  42. 单选框标签:
  43. type:radio
  44. value:单选框的值
  45. name:表示组
  46. checked:默认选中
  47. <input type="radio" value="boy" name="sex"/>
  48. 隐藏域:文本隐藏域,但表单提交后值仍然存在
  49. type:hidden
  50. <input type="hidden" value="boy" name="sex"/>
  51. -->
  52. <p>性别:
  53. <input type="hidden" value="boy" name="sex"/>
  54. <input type="radio" value="boy" name="sex" checked/>
  55. <input type="radio" value="girl" name="sex"/>
  56. </p>
  57.  
  58. <!--
  59. 多选框标签:
  60. type:checkbox
  61. checked:默认选中
  62. disabled:禁用属性
  63. <input type="checkbox" value="sleep" name="hobby"/>
  64. -->
  65. <p>爱好:
  66. <input type="checkbox" value="sleep" name="hobby"/>睡觉
  67. <input type="checkbox" value="code" name="hobby" checked/>敲代码
  68. <input type="checkbox" value="chat" name="hobby"/>聊天
  69. <input type="checkbox" value="game" name="hobby" disabled/>游戏
  70. </p>
  71.  
  72. <!--
  73. 按钮:
  74. input type="button" 普通按钮
  75. input type="image" 图像按钮
  76. input type="submit" 提交按钮
  77. input type="reset" 重置按钮
  78. more...
  79. -->
  80. <p>普通按钮:
  81. <input type="button" name="btn1" value="点击按钮"/>
  82. </p>
  83.  
  84. <p>图像按钮:
  85. <input type="image" src="../resources/image/1.jpg" name="btn1" width="50px" height="50px"/>
  86. </p>
  87.  
  88. <!--
  89. 下拉框_下拉框:
  90. selected:默认选中
  91. <select name="列表名称">
  92. <option value="选项的值">下拉选择值</option>
  93. <option value="选项的值">下拉选择值</option>
  94. <option value="选项的值" selected>下拉选择值</option>
  95. <option value="选项的值">下拉选择值</option>
  96. </select>
  97. -->
  98. <p>国家:
  99. <select name="country">
  100. <option value="china">中国</option>
  101. <option value="us">美国</option>
  102. <option value="switzerland" selected>瑞士</option>
  103. <option value="india">印度</option>
  104. </select>
  105. </p>
  106.  
  107. <!--
  108. 文本域:
  109. cols="50":50列
  110. rows="10":10行
  111. <textarea name="textarea" cols="50" rows="10">文本内容</textarea>
  112. -->
  113. <p>反馈:
  114. <textarea name="textarea" cols="50" rows="10">请输入文本内容...</textarea>
  115. </p>
  116.  
  117. <!--
  118. 文件域:
  119. type:file
  120. <input type="file" name="files"/>
  121. -->
  122. <p>上传文件:
  123. <input type="file" name="files"/>
  124. <input type="button" value="上传" name="upload"/>
  125. </p>
  126.  
  127. <!--
  128. 邮件验证:
  129. type:email
  130. required:判空
  131. <input type="email" name="email"/>
  132. -->
  133. <p>邮箱:
  134. <input type="email" name="email" required/>
  135. </p>
  136.  
  137. <!--
  138. URL:
  139. type:url
  140. <input type="url" name="url"/>
  141. -->
  142. <p>URL:
  143. <input type="url" name="url"/>
  144. </p>
  145.  
  146. <!--
  147. 数字:
  148. type:number
  149. max:最大值
  150. min:最小值
  151. step:步长
  152. <input type="number" name="num" max="100" min="0" step="10"/>
  153. -->
  154. <p>商品数量:
  155. <input type="number" name="num" max="100" min="0" step="1"/>
  156. </p>
  157.  
  158. <!--
  159. 滑块:
  160. type:range
  161. max:最大值
  162. min:最小值
  163. step:步长
  164. <input type="range" name="voice" max="100" min="0" step="2"/>
  165. -->
  166. <p>音量:
  167. <input type="range" name="voice" max="100" min="0" step="2"/>
  168. </p>
  169.  
  170. <!--
  171. 搜索框:
  172. type:search
  173. <input type="search" name="search"/>
  174. -->
  175. <p>搜索:
  176. <input type="search" name="search"/>
  177. </p>
  178.  
  179. <!--
  180. 增强鼠标可用性:
  181. 点击左侧文字,光标可跳转到指定 id 所在的标签内
  182. for:指向需跳转的标签 id
  183. -->
  184. <p>增强鼠标可用性:
  185. <label for="mark">你点我试试</label>
  186. <input type="text" id="mark">
  187. </p>
  188.  
  189. <!--
  190. 自定义邮箱:
  191. pattern:正则表达式
  192. 常用正则表达式:https://www.jb51.net/tools/regexsc.htm
  193. -->
  194. <p>自定义邮箱:
  195. <input type="text" name="mail" pattern="/^([a-z0-9_\.-]+)@([\da-z\.-]+)\.([a-z\.]{2,6})$/
  196. /^[a-z\d]+(\.[a-z\d]+)*@([\da-z](-[\da-z])?)+(\.{1,2}[a-z]+)+$/或\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*">
  197. </p>
  198.  
  199. <p>
  200. <input type="submit" value="提交表单"/>
  201. <input type="reset" value="清空表单"/>
  202. </p>
  203. </form>
  204.  
  205. </body>
  206. </html>

 

原文链接:http://www.cnblogs.com/ming2/p/14380755.html

 友情链接:直通硅谷  点职佳  北美留学生论坛

本站QQ群:前端 618073944 | Java 606181507 | Python 626812652 | C/C++ 612253063 | 微信 634508462 | 苹果 692586424 | C#/.net 182808419 | PHP 305140648 | 运维 608723728

W3xue 的所有内容仅供测试,对任何法律问题及风险不承担任何责任。通过使用本站内容随之而来的风险与本站无关。
关于我们  |  意见建议  |  捐助我们  |  报错有奖  |  广告合作、友情链接(目前9元/月)请联系QQ:27243702 沸活量
皖ICP备17017327号-2 皖公网安备34020702000426号