博客列表 >HTML常用元素(链接、列表、表格、表单)-------PHP十一期线上培训班 学号:510251 04月03日作业

HTML常用元素(链接、列表、表格、表单)-------PHP十一期线上培训班 学号:510251 04月03日作业

赵大叔
赵大叔原创
2020年04月04日 11:54:38657浏览

HTML常用元素

1、链接

属性 描述
href="url地址" 跳转的目标地址
href="mailto: 1815810057@qq.com" 发邮件
href="tel:183****9413" 打电话
href="demo3.zip" 下载 浏览器不能解析的文档
href="#a + 设置锚点的id" 锚点
target="__self" 当前窗口打开
target="_blank" 新窗口打开

实例演示代码:

  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <title>链接元素</title>
  6. </head>
  7. <body>
  8. <!--1、链接到网址-->
  9. <!--/*taget属性:-->
  10. <!--* _self: 当前窗口打开-->
  11. <!--* _blank: 新窗口打开-->
  12. <!--*-->
  13. <!--*/-->
  14. <a href="www.dashushu.club/demo1.php" target="_blank">赵大叔的网页</a>
  15. <!--2、下载html不能解析的文件-->
  16. <!--/*-->
  17. <!--* download属性:指定下载文件名-->
  18. <!--*/-->
  19. <a href="DASHU.rar" download="下载大叔文件">下载文件</a>
  20. <!--3、发邮件-->
  21. <a href="mailto:1815810057@qq.com">发邮件</a>
  22. <!--4、打电话-->
  23. <a href="tel:1831445****">打电话</a>
  24. <!--5、锚点-->
  25. <a href="#anchor">锚点</a>
  26. <h3 id="anchor" style="margin-top: 1000px;">锚点</h3>
  27. </body>
  28. </html>

代码效果:
http://www.dashushu.club/homework0403/demo1.html

2、列表

序号 标签 描述
1 <ol>, <li> 无序列表
2 <ul>, <li> 有序列表
3 <dl>, <dt>,<dd> 自定义列表

实例演示代码:

  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <title>列表元素</title>
  6. </head>
  7. <body>
  8. <!--1、有序列表-->
  9. <h3>购物清单</h3>
  10. <!--start="3":设置开始编号-->
  11. <ol start="3">
  12. <li>苹果1斤</li>
  13. <li>西瓜3斤</li>
  14. <li>橘子1斤</li>
  15. <li>葡萄1斤</li>
  16. <li>香蕉1斤</li>
  17. </ol>
  18. <hr>
  19. <!--2、无序列表:最重要的使用场景,与链接标签配合,生成导航-->
  20. <h3>导航列表</h3>
  21. <ul>
  22. <li><a href="">标签1</a></li>
  23. <li><a href="">标签2</a></li>
  24. <li><a href="">标签3</a></li>
  25. </ul>
  26. <hr>
  27. <!--3、自定义列表:类似名词解释-->
  28. <dl>
  29. <!-- dt标题-->
  30. <dt>联系地址</dt>
  31. <dd>中国.云南.昆明</dd>
  32. </dl>
  33. </body>
  34. </html>

代码效果:
http://www.dashushu.club/homework0403/demo2.html

3、表格

3.1 表格元素

序号 标签 描述
1 <table> 声明表格, 必选
2 <caption> 定义表格标题,可选
3 <thead> 定义表格头格, 只需定义一次, 可选
4 <tbody> 定义表格主体, 允许定义多次 ,必选
5 <th> 定义表格头部中的单元格, 必选
6 <tr> 定义表格中的行, 必选
7 <td> 定义表格主体中的单元格, 必选
8 <tfoot> 定义表格底, 只需定义一次, 可选

3.3 常用属性

序号 属性 所属标签 描述
1 border <table> 添加表格框
2 cellpadding <table> 设置单元格内边距
3 cellspacing <table> 设置单元格边框间隙
4 align 不限 设置单元格内容水平居中
5 bgcolor 不限 设置背景色
6 width 不限 设置宽度
7 height 不限 设置高度

实例演示代码:

  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <title>表格元素</title>
  6. </head>
  7. <body>
  8. <!--table:表格声明-->
  9. <table border="1" cellpadding="6" cellspacing="0" width="500" align="center">
  10. <!--colgroup:按列分组-->
  11. <colgroup bgcolor= ""> <!-- 设置默认背景-->
  12. <col>
  13. <col bgcolor= "">
  14. <!-- <col span = "2">:跨越2列-->
  15. <col span = "2">
  16. <col bgcolor= "">
  17. <col>
  18. <col bgcolor="red">
  19. </colgroup>
  20. <!-- caption:定义表格标题-->
  21. <caption style="font-size: 1.5rem; margin-bottom: 10px">
  22. 工资明细表
  23. </caption>
  24. <!-- thead:定义表格头部,可选-->
  25. <thead bgcolor="lightblue"> <!-- thead/tr:定义表格头部,可选-->
  26. <tr>
  27. <th>部门</th>
  28. <th>ID</th>
  29. <th>MSNV</th>
  30. <th>姓名</th>
  31. <th>工作天</th>
  32. <th>应发</th>
  33. <th>实领</th>
  34. </tr>
  35. </thead>
  36. <!-- tbody:定义表格主体,必选-->
  37. <tbody>
  38. <tr>
  39. <th rowspan="5">车间管理</th> <!-- rowspan="5":合并行,合并后,多余的要删除-->
  40. <td>1</td>
  41. <td>TH000050</td>
  42. <td>啊黎</td>
  43. <td>26</td>
  44. <td>6000</td>
  45. <td>5600</td>
  46. </tr>
  47. <tr>
  48. <!--<th>车间管理</th>-->
  49. <td>2</td>
  50. <td>TH000051</td>
  51. <td>啊仁</td>
  52. <td>26</td>
  53. <td>6000</td>
  54. <td>5600</td>
  55. </tr>
  56. <tr>
  57. <!--<th>车间管理</th>-->
  58. <td>3</td>
  59. <td>TH000054</td>
  60. <td>啊清</td>
  61. <td>26</td>
  62. <td>6000</td>
  63. <td>5600</td>
  64. </tr>
  65. <tr>
  66. <!--<th>车间管理</th>-->
  67. <td>4</td>
  68. <td>TH000056</td>
  69. <td>啊梅</td>
  70. <td>26</td>
  71. <td>6000</td>
  72. <td>5600</td>
  73. </tr>
  74. <tr>
  75. <!--<th>车间管理</th>-->
  76. <td>5</td>
  77. <td>TH000098</td>
  78. <td>啊秀</td>
  79. <td>26</td>
  80. <td>6000</td>
  81. <td>5600</td>
  82. </tr>
  83. </tbody>
  84. <!-- tfooter:定义表格尾部,可选-->
  85. <tfoot>
  86. <tr bgcolor="#ffe4c4">
  87. <td>备注</td>
  88. <td colspan="6">主管以上人员工资保密!!!</td> <!--合并列-->
  89. <!--<td></td>-->
  90. <!--<td></td>
  91. <td></td>
  92. <td></td>
  93. <td></td>-->
  94. </tr>
  95. </tfoot>
  96. </table>
  97. </body>
  98. </html>

代码效果:
http://www.dashushu.club/homework0403/demo3.html

4、 <form>表单

4.1 表单元素类型

序号 元素 名称 描述
1 <form> 表单容器 表单应该放在该标签内提交
2 <input> 输入控件 type属性指定控件类型
3 <label> 控件标签 用于控件功能描述与内容关联
4 <select> 下拉列表 用于选择预置的输入内容
5 <datalist> 预置列表 用于展示预置的输入内容
6 <option> 预置选项 <select>,<datalist>配合
7 <textarea> 文本域 多行文本框,常与富文本编辑器配合
8 <button> 按钮 用于提交表单

4.2 表单元素对应的属性

序号 元素 属性
1 <form> action, method
2 <label> for
3 <input> type, name,value,placeholder
4 <select> name
5 <datalist> id,与<input list="">关联
6 <option> value, label,selected
7 <textarea> cols, rows,name
8 <button> type,name

4.3 表单元素的公共属性(并非所有元素都具备)

序号 属性 描述
1 name 元素/控件名称,用做服务器端脚本的变量名称
2 value 提交到服务器端的数据
3 placeholder 输入框的提示信息
4 form 所属的表单,与<form name="">对应
5 autofocus 页面加载时,自动获取焦点
6 required 必填 / 必选项
7 readonly 该控件内容只读
8 disabled 是否禁用

4.4 <input>type类型

序号 属性 名称 描述
1 type="text" 文本框 默认值
2 type="password" 密码框 输入内容显示为*,不显示明文
3 type="radio" 单选按钮 多个选项中仅允许提交一个(应提供默认选项)
4 type="checkbox" 复选框 允许同时提交一个或多个选项(应提供默认选项)
5 type="hidden" 隐藏域 页面不显示,但数据仍会被提交
6 type="file" 文件上传 本地文件上传,有accept,multiple属性
7 type="submit" 提交按钮 点击后会提交按钮所在的表单
8 type="reset" 重置按钮 点击后会重置输入控件中的内容为默认值
9 type="button" 自定义按钮 使用JS脚本定义按钮点击后的行为

4.5 其它type类型(部分)

序号 属性 名称 描述
1 type="email" 邮箱 输入必须是邮箱格式
2 type="number" 整数 输入必须是整数,可设置范围min,max
3 type="url" URL地址 输入内容必须是有效的URL格式文本
4 type="search" 搜索框 通常与autocomplete配合
5 type="hidden" 隐藏域 页面不显示,但数据仍会被提交
6 type="date" 日期控件 不同浏览器显示略有不同,但功能一致
7 type="color" 调色板 可直接选择颜色, 不同平台略有不同
8 type="tel" 电话号码 手机端会弹出数字小键盘

实例演示代码:

  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <title>表单元素</title>
  6. <style>
  7. form {
  8. padding: 20px;
  9. box-sizing: border-box;
  10. width: 350px;
  11. box-shadow: 0 0 8px #666666;
  12. border-radius: 10px;
  13. margin: auto;
  14. background-color: dodgerblue;
  15. display: grid;
  16. gap: 15px;
  17. }
  18. form > section {
  19. display: grid;
  20. grid-template-columns: 65px 1fr ;
  21. }
  22. h3 {
  23. text-align: center;
  24. }
  25. input[type="image"] {
  26. justify-self: center;
  27. }
  28. </style>
  29. </head
  30. <body>
  31. <h3>用户注册</h3>
  32. <form action="">
  33. <section> <!--<section>之间垂直排列-->
  34. <!--type='text':文本框-->
  35. <label for="name">用户名:</label> <!--for属性绑定id,实现点击自动焦点-->
  36. <input type="text" id="name" name="username">
  37. </section>
  38. <section> <!--<section>之间垂直排列-->
  39. <!--type='password':密码-->
  40. <label for="psd">密码:</label> <!--for属性绑定id,实现点击自动焦点-->
  41. <input type="password" id="psd" name="password"> <!--name="password"提交表单到服务器的变量名-->
  42. </section>
  43. <section> <!--<section>之间垂直排列-->
  44. <!--type="email":密码-->
  45. <label for="email">邮箱:</label>
  46. <input type="email" id="email" name="email" placeholder="example@email.com" required>
  47. </section>
  48. <!--type="radio":单选框-->
  49. <section>
  50. <label for="secret">性别:</label>
  51. <div class="box">
  52. <!--name值要下样才能实现单选-->
  53. <input type="radio" name="gender" id="male"><label for="male"></label>
  54. <input type="radio" name="gender" id="female"><label for="female"></label>
  55. <input type="radio" name="gender" id="secret"><label for="secret">保密</label>
  56. </div>
  57. </section>
  58. <!--type="checkbox":复选框-->
  59. <section>
  60. <label for="anh">爱好:</label>
  61. <div class="boxs">
  62. <!--name值用数组形式,方便后台处理-->
  63. <!--checked默认选项-->
  64. <input type="checkbox" name="hobby[]" id="programme" value="programme" checked><label for="programme">编程</label>
  65. <input type="checkbox" name="hobby[]" id="game" value="game"><label for="game">游戏</label>
  66. <input type="checkbox" name="hobby[]" id="math" value="math"><label for="math">数学</label>
  67. <input type="checkbox" name="hobby[]" id="anh" value="anh"><label for="anh">英语</label>
  68. </div>
  69. </section>
  70. <!-- select+option:下拉列表-->
  71. <section>
  72. <label for="edu">学历:</label>
  73. <select name="edu" id="edu">
  74. <option value="1" label="高中">
  75. <option value="2" label="本科" selected>
  76. <option value="3" label="研究生">
  77. <option value="4" label="博士">
  78. </select>
  79. </section>
  80. <!--选项列表-->
  81. <section>
  82. <label for="brand">国籍:</label>
  83. <input type="search" list="nationality" name="brand" id="brand">
  84. <datalist id="nationality">
  85. <option value="CH">
  86. <option value="USA" >
  87. <option value="VN">
  88. </datalist>
  89. </section>
  90. <!--隐藏域: 数据可以提交, 但页面中没有显示,适合发送敏感或不需要用户输入的数据-->
  91. <section>
  92. <input type="hidden" name="user_id" value="1040">
  93. </section>
  94. <!--文件上传-->
  95. <section>
  96. <label for="uploads">上传头像:</label>
  97. <input type="file" name="user_pic" id="uploads" accept="image/png, image/jpeg, image/gif">
  98. </section>
  99. <!--按钮-->
  100. <button>提交</button>
  101. <input type="submit" value="注册" name="submit">
  102. <input type="reset" value="重填" name="reset">
  103. </form>
  104. </body>
  105. </html>

代码效果:
http://www.dashushu.club/homework0403/demo4.html

5. 注意事项

  • 添加disabled禁用属性的字段数据不会被提交,但是readonly只读属性的字段允许提交
  • 隐藏域的内容不会在HTML页面中显示,但是value属性的数据会被提交
声明:本文内容转载自脚本之家,由网友自发贡献,版权归原作者所有,如您发现涉嫌抄袭侵权,请联系admin@php.cn 核实处理。
全部评论
文明上网理性发言,请遵守新闻评论服务协议