【HTML】【补充】form

form

1. 属性

accept-charset charset_list 规定服务器可处理的表单数据字符集。
action URL  
autocomplete

on / off

规定是否启用表单的自动完成功能。
enctype
  • application/x-www-form-urlencoded
  • multipart/form-data 

  • text/plain  

  • application/json

规定是否字符编码
method

get / post

 
name form_name 规定表单的名称。
novalidate novalidate 如果使用该属性,则提交表单时不进行验证(如input的type是email)。
target

_blank/ _self/ _parent/ _top/ framename

规定在何处打开 action URL。
  •  method:

1. get:

表单数据会被encodeURIComponent后以参数的形式:name1=value1&name2=value2附带在url?后面,再发送给服务器,并在url中显示出来

GET http://www.example.com/example/program?user_name=张三&user_passwd=123

2. post:

所有键值对会连接成一行,数据放在消息主体(entity-body)中传送。

POST /handling-page HTTP/1.1
Host: example.com
Content-Type: application/x-www-form-urlencoded
Content-Length: 74

user_name=张三&user_passwd=123
  • enctype:

当 method=post 时,enctype规定传送数据是否编码。当method=get时,enctype失效。

1. application/x-www-form-urlencoded(默认值)

Content-Type: application/x-www-form-urlencoded

title=test&sub%5B%5D=1&sub%5B%5D=2&sub%5B%5D=3

以键值对key1=val1&key2=val2 的方式进行编码,然后key 和 val 都进行了URL 转码

2. multipart/form-data

使用场景:表单上传文件。数据将以混合的格式发送。

BASHPOST http://www.example.com HTTP/1.1
Content-Type:multipart/form-data; boundary=----WebKitFormBoundaryrGKCBY7qhFd3TrwA

------WebKitFormBoundaryrGKCBY7qhFd3TrwA
Content-Disposition: form-data; name="text"

title
------WebKitFormBoundaryrGKCBY7qhFd3TrwA
Content-Disposition: form-data; name="file"; filename="chrome.png"
Content-Type: image/png

PNG ... content of chrome.png ...
------WebKitFormBoundaryrGKCBY7qhFd3TrwA--

3. text/plain

数据将以纯文本格式发送

Content-Type: text/plain

foo=bar
baz=The first line.
The second line.

4.application/json

发送的是序列化的json字符串

BASHPOST http://www.example.com HTTP/1.1 
Content-Type: application/json;charset=utf-8

{"title":"test","sub":[1,2,3]}

 

 

你可能感兴趣的:(【HTML】【补充】form)