博客列表 >自主练习4_表单练习(直播跟练版)

自主练习4_表单练习(直播跟练版)

柏拉图
柏拉图原创
2022年10月18日 22:21:47275浏览

表单常用标签如下:

  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. <!-- ! 用户注册 -->
  12. <h2 class="title">用户注册</h2>
  13. <!--
  14. * 1. action : 服务器上的表单处理脚本,如login.php
  15. * 2. method : 提交方式
  16. * 2.1 GET : 默认,数据在URL中,适用于"少量且公开"的数据,如分页,查询参数
  17. * 2.2 POST : 数据在请求体中,适合于"大量的或隐私的"数据,如卡号
  18. * 3. enctype :
  19. * 3.1 application / x-www-form-urlencoded : 默认对值对的编码方案
  20. * 3.2 multipart/form-data : 分块,原始数据,适用文件上传
  21. * 4. target : 与<a>相同,_self是默认,_blank新页面展示
  22. * 5. id : name现在已经废弃了,全用id来引用该表单
  23. * 6. onsubmit : 提交时执行的js,拦截提交操作,执行用户自定义提交行为
  24. -->
  25. <form action="register.php" method="POST" enctype="multipart/form-data" target="_blank">
  26. <!-- 表单控件分组 -->
  27. <fieldset>
  28. <legend>基本信息</legend>
  29. <!-- ? type="text" 单行文本框,明文 -->
  30. <div class="username">
  31. <!-- ? label+input -->
  32. <!-- ? label 与 input 绑定: label _for = input.id -->
  33. <label for="uname">用户名:</label>
  34. <!-- ? name + value : 名值对组合 -->
  35. <!-- ? required : 布尔属性,必选项 -->
  36. <!-- ? readonly : 只读,不能输入,但会被提交 -->
  37. <!-- ? disabled : 禁用,只能看,不能改,不能提交 -->
  38. <input type="text" id="uname" name="username" value="" placeholder="用户名不少6位" required readonly disabled/>
  39. </div>
  40. <!-- ? type = “password” 单行,密文 -->
  41. <div class="password">
  42. <!-- ? label + input -->
  43. <label for="psw">密码:</label>
  44. <!-- ? name + value -->
  45. <!-- ? placeholder 与 value 不能共存,否则以value为主,value是默认值 -->
  46. <input type="password" name="password" id="psw" value="123456" />
  47. <button type="button" onclick="this.previousElementSiBling.type='text'">显示密码</button>
  48. </div>
  49. <!-- ? type = "email" 自带验证规则 -->
  50. <div class="email">
  51. <label for=""></label>
  52. <input type="email" id="email" name="email" value="" placeholder="user@email">
  53. </div>
  54. <!-- ? type = number -->
  55. <div class="age">
  56. <label for="age">年龄:</label>
  57. <!--
  58. * 1. min : 最小值
  59. * 2. max : 最大值
  60. * 3. step : 递增或者是递减的量
  61. -->
  62. <input type="number" value="" min="18" max="80" step="10" />
  63. </div>
  64. <!-- ? typr= "date" -->
  65. <div class="brithday">
  66. <label for="birthday">生日:</label>
  67. <input type="date" name="birthday" value="2022-10-18" id="birthday" min="1949-10-01" max="2000-1-1" />
  68. </div>
  69. <!-- ? type = url -->
  70. <div class="blog">
  71. <label for="blog">Blog:</label>
  72. <input type="url" name="blog" placeholder="http://" />
  73. </div>
  74. <!-- ? type = color -->
  75. <div class="color">
  76. <label for="color">拾色器:</label>
  77. <input type="color" name="color" value="#FFFF00" id="color" onchange="getColor(this)">
  78. <output>#FFFF00</output>
  79. </div>
  80. <!-- ? type = search -->
  81. <div class="search">
  82. <label for="query">搜索:</label>
  83. <input type="search" name="search" id="query" placeholder="输入关键字">
  84. <button type="button">查询</button>
  85. </div>
  86. </fieldset>
  87. <fieldset>
  88. <legend>其他信息</legend>
  89. <!-- ? type = "file" -->
  90. <div class="upload">
  91. <label for="upload">头像:</label>
  92. <!-- ! 文件上传,必须将 form.enctype = "multipart/form-data,method="POSt" -->
  93. <input type="file" name="user_pic" id="upload">
  94. <button type="button">上传</button>
  95. </div>
  96. <!-- ? type = "hidden" 隐藏域,页面不可见,但数据可以正常提交到服务器中 -->
  97. <input type="hidden" name="uid" value="10102" />
  98. <!-- ? type = "range" 滑动块 -->
  99. <div class="range">
  100. <label for="range">星级::</label>
  101. <input type="range" name="range" id="range" min="0" max="5" value="0" step="1" oninput="" />
  102. <!-- <span></span> -->
  103. <output>0</output>
  104. </div>
  105. <!-- ? 进度条:是标签 -->
  106. <div class="progress">
  107. <label>进度:</label>
  108. <!-- min 不要给 -->
  109. <progress name="progress" max="100" value="10"></progress>
  110. <output>10%</output>
  111. <button type="button">+1</button>
  112. </div>
  113. </fieldset>
  114. <fieldset>
  115. <legend>预置内容</legend>
  116. <!-- 1.用户自行输入:具有很大的分享,需要不断地验证 -->
  117. <!-- 2.预置内容,用户只要选择就可以:安全性高,但是失去了灵活性 -->
  118. <!-- ? type = "radio" 单选按钮 -->
  119. <div class="gender">
  120. <label for="secret"></label>
  121. <!--
  122. * 1. name : 必须相同,以保证唯一性
  123. * 2. input.value = input.id = label.for
  124. * 3. checked : 默认选项
  125. * 4.总标签 label.for = checked
  126. -->
  127. <input type="radio" name="gender" value="male" id="male" /><label for="male"></label>
  128. <input type="radio" name="gender" value="female" id="female" /><label for="female"></label>
  129. <input type="radio" name="gender" value="secret" id="secret" checked/><label for="secret">保密</label>
  130. </div>
  131. <!-- ? type = "checkbox" 复选框 -->
  132. <div class="hobby">
  133. <label>爱好:</label>
  134. <!--
  135. * 1. name : hobby[],数组的语法形式,用于保存一个或多个值
  136. * 2. input.value = input.id = label.for,其实只需要input.id = label.for 即可
  137. * 3. checked : 默认选项
  138. -->
  139. <input type="checkbox" name="hobby[]" value="game" id="" checked><label for="game">游戏</label>
  140. <input type="checkbox" name="hobby[]" value="trave" id=""><label for="trave">摄影</label>
  141. <input type="checkbox" name="hobby[]" value="shoot" id=""><label for="shoot">编程</label>
  142. <input type="checkbox" name="hobby[]" value="programe" id="" checked><label for="programe">旅游</label>
  143. </div>
  144. <!-- ? select + option :下拉列表 -->
  145. <div class="edu">
  146. <label for="edu">学历:</label>
  147. <!--
  148. * 1. name 与 value,名值,分布在两个标签中。select.name , option.value
  149. * 2. selected : 默认选项
  150. * 3. 选择过多,且有规律,建议分组展示:optgroup
  151. * 4. 为select家提示:selected + disable , 加到第一项之前
  152. * 5. multiple : 支持多选
  153. -->
  154. <select name="" id="">
  155. <option value="0">文盲</option>
  156. <optgroup label="义务教育">
  157. <option value="1">小学</option>
  158. <option value="2" selected>初中</option>
  159. </optgroup>
  160. <optgroup label="高等教育">
  161. <option value="3">高中</option>
  162. <option value="4">大学</option>
  163. <option value="5">硕士</option>
  164. <option value="6">博士</option>
  165. </optgroup>
  166. </select>
  167. </div>
  168. <!-- ? 自带联想提示:预定义 + 自定义,即可自己输入,也能从预置中选择:input + select -->
  169. <!-- ? input + datalist + option -->
  170. <div class="like">
  171. <label for="keyword">语言:</label>
  172. <input type="search" name="language" list="details" id="keyword">
  173. <!-- 预置值列表 -->
  174. <!-- ? input.list == detailst.id 进行绑定 -->
  175. <datalist id="details">
  176. <option value="html">html</option>
  177. <option value="css">css</option>
  178. </datalist>
  179. </div>
  180. </fieldset>
  181. <div>
  182. <!-- 文本域:多行文本框,input:单行文本框 -->
  183. <label for="comment">个人简介:</label>
  184. <!-- ? textarea : 没有 value 属性,它的值位于textarea标签之间 -->
  185. <textarea name="comment" id="comment" cols="30" rows="5">hello world</textarea>
  186. </div>
  187. <!-- ? form中的button,默认为提交 -->
  188. <button>提交</button>
  189. <!-- 等价于 -->
  190. <button type="submit">提交</button>
  191. <!-- ? type = "button" : 只是一个普通的按钮,没有预置行为,如提交,复位 -->
  192. <button type="button">提交</button>
  193. <!--
  194. * 如果想将表单的同步提交,改为异步提交(Ajax,Fetch),有三种方式:
  195. * 1. <button type="button">
  196. * 2. 事件方法中: event.preventDefault(),禁用默认行为
  197. * 3. form.onsubmit = "return false",禁用当前表单默认提交行为
  198. -->
  199. <!-- ! 每个表单控件都有一个表单属性,它永远指向当前的表单元素 -->
  200. </form>
  201. <script src="static/js/func.js"></script>
  202. </body>
  203. </html>
声明:本文内容转载自脚本之家,由网友自发贡献,版权归原作者所有,如您发现涉嫌抄袭侵权,请联系admin@php.cn 核实处理。
全部评论
文明上网理性发言,请遵守新闻评论服务协议