form表单
- 能够获取用户输入(包括输入, 选择和上传文件)
- 将用户的输入内容全部发送给后端
参数
- action 向何处提交
- 不写, 默认朝当前页面所在地址提交数据
- 全写路径 (https://www.google.com)
- 只写路径后缀 (/index/)
- method 如何提交 (提交方式)
- get (默认)
- post
- enctype 规定被提交数据的编码
input
- type
type参数 | 功能 |
---|---|
text | 普通文本 |
password | 密码输入框 |
date | 日期输入框 |
邮箱输入框 | |
radio | 单选框 |
checkbox | 复选框 |
file | 文本选择框 |
button | 普通按钮 |
reset | 重置按钮 |
submit | 提交按钮 |
hidden | 隐藏输入框 |
- checked 预先选定
- type=radio
- type=checkbox
- disable 不可更改
- value 默认值
- 按钮的名称
label
- 和input联用, 不会呈现任何效果
- 聚焦功能, 将焦点转到input输入框中
select
- 下拉选择框
- multiple 可多选
textarea
- 大段文本输入框
注意
- 触发form表单提交数据的两个标签
- input标签
type=submit
- button标签
- input标签
- 所有获取用户输入的标签, 都应该有name属性
- name属性类似于字典的key
- input框获取到的数据会放到input框的value属性中
- 选择框传到后端的数据, 由value属性决定
- 如果要提交包含文件上传控件的表单, 必须修改以下参数
enctype="multipart/form-data"