HTML <form> 标签的 enctype 属性
form 标签的 enctype 属性是规定在发送到服务器之前应该如何对表单数据进行编码。
实例
在下面的例子中,表单数据会在未编码的情况下进行发送:
<html><body><form action="/example/html/html_form.aspx" method="get" enctype="text/plain">姓氏: <input type="text" name="fname"><br>名字: <input type="text" name="lname"><br><input type="submit" value="Submit"></form><p>请单击确认按钮,输入会发送到服务器上名为 "html_form.aspx" 的页面。</p></body></html>
定义和用法
enctype 属性规定在发送到服务器之前应该如何对表单数据进行编码。
默认地,表单数据会编码为 "application/x-www-form-urlencoded"。就是说,在发送到服务器之前,所有字符都会进行编码(空格转换为 "+" 加号,特殊符号转换为 ASCII HEX 值)。
语法
<form enctype="value">
属性值
| 值 | 描述 |
|---|---|
| application/x-www-form-urlencoded | 在发送前编码所有字符(默认) |
| multipart/form-data | 不对字符编码。 在使用包含文件上传控件的表单时,必须使用该值。 |
| text/plain | 空格转换为 "+" 加号,但不对特殊字符编码。 |