Blogger Information
Blog 3
fans 0
comment 0
visits 1075
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
入门HTML (二)实战!制作行与列的合并的课程表(带Emment语法),制作注册表单
良药
Original
409 people have browsed it

入门HTML(二)表格与表单

内容

  • 制作行与列的合并的课程表
  • 制作注册表单

    一、制作行与列的合并的课程表

  1. <!--
  2. <table>是复合元素: 需要多个标签进行描述
  3. 1. table: 表格容器
  4. 2. caption: 表格标题(可选)
  5. 3. tr: 表格中的行
  6. 4. td/th: 单元格(列),数据容器,必须写到<tr>内部
  7. th与td区别在于多了"加粗和居中"样式,学用在thead中
  8. -->
  9. <table border="1" width="400">
  10. <caption>
  11. <h2>课程表</h2>
  12. </caption>
  13. <!-- 表头 thead>tr>th -->
  14. <thead>
  15. <tr>
  16. <th>课程/星期</th>
  17. <th>星期一</th>
  18. <th>星期二</th>
  19. <th>星期三</th>
  20. <th>星期四</th>
  21. <th>星期五</th>
  22. </tr>
  23. </thead>
  24. <tbody>
  25. <!-- 表体 -->
  26. <!-- tr*8>td{x}*6 -->
  27. <tr>
  28. <!-- 垂直合并 rowspan-->
  29. <th rowspan="4">上午</th>
  30. <td>数学</td>
  31. <td>语文</td>
  32. <td>英语</td>
  33. <td>数学</td>
  34. <td>语文</td>
  35. </tr>
  36. <tr>
  37. <!-- 第2行第1列 -->
  38. <!-- <td>x</td> -->
  39. <td>语文</td>
  40. <td>数学</td>
  41. <td>语文</td>
  42. <td>语文</td>
  43. <td>数学</td>
  44. </tr>
  45. <tr>
  46. <!-- 第3行第1列 -->
  47. <!-- <td>x</td> -->
  48. <td>音乐</td>
  49. <td>英语</td>
  50. <td>科学</td>
  51. <td>英语</td>
  52. <td>英语</td>
  53. </tr>
  54. <tr>
  55. <!-- 第4行第1列 -->
  56. <!-- <td>x</td> -->
  57. <td>历史</td>
  58. <td>体育</td>
  59. <td>体活</td>
  60. <td>电脑</td>
  61. <td>道德</td>
  62. </tr>
  63. <!-- 从第6行第1列开始,合并6列 -->
  64. <!-- 水平方向 colspan-->
  65. <!-- 将合并属性必须添加到第一个th中,并使用第1个th中的数据 -->
  66. <tr>
  67. <th bgcolor="lightblue" colspan="6">午休</th>
  68. </tr>
  69. <tr>
  70. <th rowspan="2">下午</th>
  71. <td>英语</td>
  72. <td>地理</td>
  73. <td>数学</td>
  74. <td>生物</td>
  75. <td>历史</td>
  76. </tr>
  77. <tr>
  78. <td>班会</td>
  79. <td>电脑</td>
  80. <td>音乐</td>
  81. <td>体育</td>
  82. <td>地理</td>
  83. </tr>
  84. <!-- 表尾 -->
  85. <tfoot>
  86. <tr>
  87. <th>晚上</th>
  88. <th colspan="5">作业</th>
  89. </tr>
  90. </tfoot>
  91. </tbody>
  92. </table>

二、制作注册表单

  1. <!--
  2. 表单: 复合元素,用多个标签描述
  3. 1. form: 表单控件的容器
  4. 2. fieldset: 表单控件分组容器
  5. 3. label: 控件标签名称
  6. 4. input: 输入控件,类型由type属性决定
  7. 5. select+option: 预定义列表框
  8. 6. input+datalist+option: 预定义与自定义列表框
  9. 7. textarea: 文本域(多行文本框)
  10. 8. button: 按钮,默认同步提交(type="submit")
  11. -->
  12. <!-- 注册表单 -->
  13. <!--
  14. 1. form.action: 后端处理表单的脚本,如 'register.php'
  15. 2. form.method: 表单数据提交方式,默认为GET
  16. (1) GET: 数据以键值对方式,添加到url中,适合数量少且可公开的数据,如页码
  17. (2) POST: 数据在请求体中, url不可见,适合大量或敏感的数据,如密码,文件上传
  18. 3. enctype: 表单数据编码方案
  19. (1) application/x-www-form-urlencoded: 默认对值对的编码方案
  20. (2) multipart/form-data: 分块,原始数据,适用文件上传
  21. 4. target: _self(默认),_blank,和a.target相同
  22. 5. id: 表单引用
  23. 6. onsubmit: 表单提交事件,返回false,可拦截提交请求
  24. -->
  25. <form action="register.php" method="POST">
  26. <fieldset style="display: inline-grid; gap: 1em">
  27. <legend>用户注册</legend>
  28. <!-- 单行文本框 -->
  29. <div class="username">
  30. <label for="uname">用户名:</label>
  31. <input type="text" name="username" placeholder="username" id="uname" autofocus />
  32. </div>
  33. <div class="my-email">
  34. <label for="my-email">邮箱:</label>
  35. <input type="email" name="my_email" id="my-email" placeholder="username@email.com" required />
  36. </div>
  37. <div class="psw">
  38. <label for="psw">密码:</label>
  39. <input
  40. type="password"
  41. name="password"
  42. id="psw"
  43. placeholder="******"
  44. required
  45. onkeydown="this.nextElementSibling.disabled=false"
  46. />
  47. <button type="button" disabled onclick="showPsw(this,this.form)">显示</button>
  48. </div>
  49. <!-- 数值类控件 -->
  50. <div class="age">
  51. <label for="age">年龄:</label>
  52. <input type="number" name="age" id="age" value="20" min="20" max="70" step="5" />
  53. </div>
  54. <!-- 日期控件 -->
  55. <div class="birthday">
  56. <label for="birthday">生日:</label>
  57. <input type="date" name="birthday" id="birthday" value="1990-01-01" min="1949-10-01" max="2003-01-01" />
  58. <!-- <input type="month" />
  59. <input type="week" />
  60. <input type="time" />
  61. <input type="datetime-local" name="" id="" /> -->
  62. </div>
  63. <!-- 其它常用控件简介 -->
  64. <!-- url控件 -->
  65. <div class="url">
  66. <label for="blog">博客:</label>
  67. <input type="url" name="url" id="blog" placeholder="http://" />
  68. </div>
  69. <!-- 拾色器 -->
  70. <div class="color">
  71. <label for="color">背景:</label>
  72. <input type="color" name="bgcolor" id="color" value="#ffff00" onchange="setBgColor(this,this.form)" />
  73. </div>
  74. <!-- 搜索框,和文本框相比,多一个清空按钮 -->
  75. <div class="search">
  76. <label for="keywords">搜索:</label>
  77. <input type="search" name="keywords" id="search" placeholder="输入关键字" />
  78. </div>
  79. <!-- 文件上传 -->
  80. <div class="upload">
  81. <label for="upload">头像:</label>
  82. <input type="file" name="user_pic" id="upload" accept="image/jpeg,image/png" />
  83. <button type="button" onclick="fileUploads(this.form)">上传</button>
  84. </div>
  85. <!-- 单选按钮 -->
  86. <div class="gender">
  87. <!-- 推荐与默认值的input.id绑定 -->
  88. <label for="secret">性别:</label>
  89. <!-- name="male",将这个键值对,做为变量与值,提交到后端脚本中处理 -->
  90. <!-- name: 必须相同,以保住唯一性 -->
  91. <input type="radio" name="gender" value="male" id="male" /><label for="male"></label>
  92. <input type="radio" name="gender" value="female" id="female" /><label for="female"></label>
  93. <!-- checked: 布尔属性, 默认选项 -->
  94. <input type="radio" name="gender" value="secret" id="secret" checked /><label for="secret">保密</label>
  95. </div>
  96. <!-- 重选框 -->
  97. <div class="hobby">
  98. <label>爱好:</label>
  99. <!--
  100. * 1. name: hobby[], 数组的语法形式,用于保存一个或多个值,这样后端处理脚本就可以获取到多个值
  101. * 2. input.value <=> input.id <=> label.for,其实只需要input.id <==> label.for
  102. * 3. checked: 默认选项
  103. -->
  104. <input type="checkbox" name="hobby[]" value="game" id="game" checked /><label for="game">游戏</label>
  105. <input type="checkbox" name="hobby[]" value="trave" id="trave" /><label for="trave">旅游</label>
  106. <input type="checkbox" name="hobby[]" value="shoot" id="shoot" /><label for="shoot">摄影</label>
  107. <input type="checkbox" name="hobby[]" value="program" id="program" checked /><label for="program">编程</label>
  108. </div>
  109. <!-- 下拉列表框 -->
  110. <div class="edu">
  111. <label for="edu">学历:</label>
  112. <!--
  113. * 1. name与value: 名值,分布在二个标签中,select.name , option.value
  114. * 2. selected: 默认选择
  115. * 3. 选择过多,且有规律,建议分组展示: optgroup
  116. * 4. 为select加提示: selected + disabled, 加到第一项之前
  117. * 5. multiple: 支持多选
  118. -->
  119. <!-- 下拉列表框, 将键与值所在的标签进行分离 -->
  120. <!-- select.name = select>option.value -->
  121. <!-- select.form="指向当前表单元素" -->
  122. <select name="edu" id="edu" form="">
  123. <!-- <select name="edu" id="edu" multiple> -->
  124. <!-- select 标签不能加提示, 想加怎么办 -->
  125. <!-- 加提示 -->
  126. <option value="" selected disabled>--请选择--</option>
  127. <option value="0">文盲</option>
  128. <!-- 下拉选项分组: 同类组合在一起 -->
  129. <optgroup label="义务教育">
  130. <option value="1">小学</option>
  131. <option value="2">初中</option>
  132. <option value="3">高中</option>
  133. </optgroup>
  134. <optgroup label="高等教育">
  135. <option value="4">专科</option>
  136. <option value="5">本科</option>
  137. <option value="6">硕士</option>
  138. <option value="7">博士</option>
  139. </optgroup>
  140. </select>
  141. </div>
  142. <!-- 预定义列表框 -->
  143. <div class="like">
  144. <label for="keyword">语言: </label>
  145. <input type="search" name="language" list="details" id="keyword" />
  146. <!-- 预置值列表 -->
  147. <!-- ? input.list <==> datalist.id 进行绑定 -->
  148. <datalist id="details">
  149. <option value="html">html</option>
  150. <option value="css">css</option>
  151. <option value="js">js</option>
  152. <option value="php">php</option>
  153. <option value="vue">vue</option>
  154. <option value="node">node</option>
  155. </datalist>
  156. </div>
  157. <!-- 文本框: 多行文本框 -->
  158. <div>
  159. <label for="comment">备注:</label>
  160. <!-- ? textarea: 没有 value 属性,它的值位于textarea标签之间 -->
  161. <!-- ? maxlength: 最大长度 -->
  162. <textarea name="comment" id="comment" cols="30" rows="5" maxlength="200" style="resize: none">
  163. Hello world
  164. </textarea>
  165. </div>
  166. <button type="submit">登录</button>
  167. </fieldset>
  168. </form>
  169. <script>
  170. function showPsw(ele, form) {
  171. const psw = form.password
  172. if (psw.type === 'password') {
  173. psw.type = 'text'
  174. ele.textContent = '隐藏'
  175. } else if (psw.type === 'text') {
  176. psw.type = 'password'
  177. ele.textContent = '显示'
  178. } else {
  179. return false
  180. }
  181. }
  182. // 设置表单背景
  183. function setBgColor(ele, form) {
  184. form.firstElementChild.style.backgroundColor = ele.value
  185. }
  186. // 文件上传
  187. function fileUploads(form) {
  188. let tips = ''
  189. if (form.user_pic.value.length === 0) {
  190. tips += '文件不能为空'
  191. } else {
  192. tips += '上传成功'
  193. }
  194. alert(tips)
  195. }
  196. </script>
Correcting teacher:PHPzPHPz

Correction status:qualified

Teacher's comments:
Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!