博客列表 >前端表格实现购物车和表单实现用户注册界面

前端表格实现购物车和表单实现用户注册界面

emagic
emagic原创
2020年06月17日 17:55:23899浏览

0616作业

一、 前端表格实现购物车(表格实现)

  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8" />
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  6. <title>表格实战: 购物车</title>
  7. <link rel="stylesheet" type="text/css" href="style.css">
  8. </head>
  9. <body>
  10. <!-- 表格 -->
  11. <table>
  12. <!-- 标题 -->
  13. <caption>
  14. 我的订单
  15. </caption>
  16. <!-- 头部 -->
  17. <thead>
  18. <tr>
  19. <th>ID</th>
  20. <th>商品</th>
  21. <th>单价/元</th>
  22. <th>单位</th>
  23. <th>数量</th>
  24. <th>金额/元</th>
  25. </tr>
  26. </thead>
  27. <!-- 主体 -->
  28. <tbody>
  29. <tr>
  30. <td>SN-101011</td>
  31. <td>2080ti显卡</td>
  32. <td>8999</td>
  33. <td></td>
  34. <td>1</td>
  35. <td>8999</td>
  36. </tr>
  37. <tr>
  38. <td>SN-102012</td>
  39. <td>144hz显示器</td>
  40. <td>5000</td>
  41. <td></td>
  42. <td>2</td>
  43. <td>10000</td>
  44. </tr>
  45. <tr>
  46. <td>SN-103013</td>
  47. <td>漫步者音箱</td>
  48. <td>399</td>
  49. <td></td>
  50. <td>5</td>
  51. <td>1995</td>
  52. </tr>
  53. <tr>
  54. <td>SN-104014</td>
  55. <td>SSD移动硬盘</td>
  56. <td>888</td>
  57. <td></td>
  58. <td>2</td>
  59. <td>1776</td>
  60. </tr>
  61. <tr>
  62. <td>SN-105015</td>
  63. <td>华硕玩家国度路由器</td>
  64. <td>1000</td>
  65. <td></td>
  66. <td>3</td>
  67. <td>3000</td>
  68. </tr>
  69. </tbody>
  70. <!-- 底部 -->
  71. <tfoot>
  72. <tr>
  73. <td colspan="4">总计:</td>
  74. <!-- 合并单元格,这里合并4格,后面要响应减掉4个<td> ,否则格式会乱-->
  75. <td>13</td>
  76. <td>25770</td>
  77. </tr>
  78. </tfoot>
  79. </table>
  80. <!-- 结算按钮 -->
  81. <div>
  82. <button>结算</button>
  83. </div>
  84. </body>
  85. </html>

css代码,通过link引入

  1. html {
  2. font-size: 14px;
  3. }
  4. table {
  5. /* 将单元格之间的间隙去掉 */
  6. border-collapse: collapse;
  7. width: 70%;
  8. margin: auto;
  9. color: #666;
  10. font-weight: lighter;
  11. text-align: center;
  12. }
  13. /* 表格线直接添加到单元格上面,线条是围绕单元格的 */
  14. table thead th,
  15. table td {
  16. border-bottom: 1px solid #ccc;
  17. padding: 10px;
  18. }
  19. /* 标题样式 */
  20. table caption {
  21. font-size: 1.5rem;
  22. margin-bottom: 15px;
  23. color: green;
  24. }
  25. table th {
  26. font-weight: lighter;
  27. color: green;
  28. }
  29. table thead tr:first-of-type {
  30. background-color: lightcyan;
  31. }
  32. /* 隔行变色 */
  33. table tbody tr:nth-of-type(even) {
  34. background-color: lightgreen;
  35. }
  36. /* 鼠标悬停效果 */
  37. table tbody tr:hover {
  38. background-color: lightblue;
  39. }
  40. /* 底部样式 */
  41. table tfoot td {
  42. border-bottom: none;
  43. color: coral;
  44. font-size: 1.2rem;
  45. font-weight: bolder;
  46. }
  47. /* 结算按钮 */
  48. /*因为只有一个按钮,实际效果last-of-type和first-of-type其实都是一样的*/
  49. body div:last-of-type {
  50. width: 70%;
  51. margin: 10px auto;
  52. }
  53. body div:first-of-type button {
  54. /* 靠右 */
  55. float: right;
  56. width: 120px;
  57. height: 32px;
  58. background-color: seagreen;
  59. color: white;
  60. border: none;
  61. /* 设置鼠标样式,变成手指的形状 */
  62. cursor: pointer;
  63. }
  64. body div:first-of-type button:hover {
  65. background-color: coral;
  66. font-size: 1.2rem;
  67. /* 改表字体相对大小 */
  68. }

购物车案例

二、表单实现用户注册界面(表单实现)

  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8" />
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  6. <title>表单用户注册界面案例</title>
  7. </head>
  8. <body>
  9. <h3>用户注册</h3>
  10. <!-- form+input.... -->
  11. <form action="" method="POST">
  12. <!-- 控件组 -->
  13. <fieldset>
  14. <legend>基本信息(必填)</legend>
  15. <div>
  16. <label for="my-username">账号:</label>
  17. <input
  18. type="text"
  19. id="my-username"
  20. name="username"
  21. placeholder="6-15位字符"
  22. autofocus
  23. />
  24. </div>
  25. <div>
  26. <label for="email-id">邮箱:</label>
  27. <input
  28. type="email"
  29. <!限制只能获取email格式>
  30. name="email"
  31. id="email-id"
  32. placeholder="demo@example.com"
  33. />
  34. </div>
  35. <!-- 密码 -->
  36. <div>
  37. <label for="pwd-2">密码:</label>
  38. <input type="password"" name="password1" id="pwd-2"
  39. placeholder="不少于6位且字母+数字" />
  40. </div>
  41. <div>
  42. <label for="pwd-1">确认:</label>
  43. <input type="password" name="password2" id="pwd-1" />
  44. </div>
  45. </fieldset>
  46. <fieldset>
  47. <legend>扩展信息(选填)</legend>
  48. <div>
  49. <label
  50. >生日:
  51. <input type="date" name="birthday" />
  52. </label>
  53. </div>
  54. <div>
  55. <!-- 单选按钮 -->
  56. <label for="secret">性别:</label>
  57. <!-- 单选按钮中的name属性名必须相同 -->
  58. <input type="radio" name="gender" value="male" id="male" /><label
  59. for="male"></label
  60. >
  61. <input type="radio" name="gender" value="female" id="female" /><label
  62. for="female"></label>
  63. <input type="radio" name="gender" value="secret" id="secret" checked/><label for="secret">保密</label>
  64. </div>
  65. <div>
  66. <!-- 复选框 -->
  67. <label for="programme">爱好</label>
  68. <!-- 因为复选框返回是一个或多个值,最方便后端用数组来处理, 所以将name名称设置为数组形式便于后端脚本处理 -->
  69. <input type="checkbox" name="hobby[]" id="game" value="game" /><label
  70. for="game"
  71. >打游戏</label
  72. >
  73. <input
  74. type="checkbox"
  75. name="hobby[]"
  76. value="shoot"
  77. id="shoot"
  78. /><label for="shoot">摄影</label>
  79. <input
  80. type="checkbox"
  81. name="hobby[]"
  82. value="programme"
  83. id="programme"
  84. checked
  85. /><label for="programme">编程</label>
  86. </div>
  87. <div>
  88. <!-- 选项列表 -->
  89. <label for="brand">地址:</label>
  90. <input type="search" list="phone" name="brand" id="brand" />
  91. <datalist id="phone">
  92. <option value="广东" label="广东"> </option>
  93. <option value="浙江" label="浙江"></option>
  94. <option value="四川" label="四川"> </option>
  95. </datalist>
  96. </div>
  97. </fieldset>
  98. <fieldset>
  99. <legend>其它信息(选填)</legend>
  100. <!--文件上传-->
  101. <div>
  102. <label for="uploads">上传头像:</label>
  103. <input
  104. type="file"
  105. name="user_pic"
  106. id="uploads"
  107. accept="image/png, image/jpeg, image/gif"
  108. />
  109. </div>
  110. <!--文本域-->
  111. <div>
  112. <label for="resume">简历:</label>
  113. <!--注意文本域没有value属性-->
  114. <textarea
  115. name="resume"
  116. id="resume"
  117. cols="30"
  118. rows="5"
  119. placeholder="不超过500字"
  120. >
序号 表单属性 特征
1 type=”text” 明文
2 type=”email” 限制只能输入邮箱格式
3 type=”date” 日期格式
4 type=”radio” 单选,单选按钮中的name属性名必须相同
5 type=”checkbox” 复选框,建议name名称设置为数组形式便于后端服务器处理
6 type=”search” 下来列表,如省市联动
7 type=”file” 文件传输
8 type=”hidden” 隐藏域, 无需用户输入但是系统需要的信息,如Id,登录的时间
  • <label for=""> for中的名称必须和id的名称一样,才能实现绑定点击文字跳转到输入框

  • 单选、复选等表单属性中设置checked 表示默认选中的项

  • name属性很重要,是传递给后台服务器的变量值

声明:本文内容转载自脚本之家,由网友自发贡献,版权归原作者所有,如您发现涉嫌抄袭侵权,请联系admin@php.cn 核实处理。
全部评论
文明上网理性发言,请遵守新闻评论服务协议