简介
enctype 属性规定在将表单数据发送到服务器之前如何对其进行编码。
只有 method=“post” 时才使用 enctype 属性。
HTML5 中 input 增加新属性 formenctype ,有类似的作用,会覆盖 form 元素的 enctype 属性
取值
application/x-www-form-urlencoded
默认。在发送前对所有字符进行编码(将空格转换为 “+” 符号,特殊字符转换为 ASCII HEX 值)。
会把表单中发送的数据编码为键值对,中文会进行 urlencoded 编码, method=“post” ,数据会封装到 http body 中发送,如果用 node http 模块接受,接受到 buffer 后转换为 string ,会得到类似 name=%E5%88%98%E9%B9%8F%E9%A3%9E&age=32&address=%E6%B7%B1%E5%9C%B3%E5%B8%82 格式的字符串,与 method=“get” 方式在url中参数的形式类似
multipart/form-data
不对字符编码,发送二进制文件数据。当使用有文件上传控件的表单时,必须设置该值。
text/plain
将空格转换为 “+” 符号,但不编码特殊字符。