HTML <button> formenctype 属性
HTML <button> 标签的 formenctype 属性用于覆盖 form 元素的 enctype 属性
该属性与 type="submit" 配合使用
语法
<button type="submit" formenctype="value">
属性值
值 | 描述 |
---|---|
application/x-www-form-urlencoded | 在发送前对所有字符进行编码(默认) |
multipart/form-data | 不对字符编码 当使用有文件上传控件的表单时 该值是必需的 |
text/plain | 将空格转换为 "+" 符号,但不编码特殊字符 |
HTML 4.01 与 HTML 5 之间的差异
formenctype 属性是 HTML 5 中的新属性
浏览器支持
Internet Explorer 10, Firefox, Opera, Chrome, 和 Safari 支持 formenctype 属性
Internet Explorer 9 及更早 IE 版本不支持 formenctype 属性
范例
带有两个提交按钮的表单,带有不同的编码方式
- 第一个提交按钮使用默认字符编码提交表单数据
- 第二个提交按钮不使用字符编码提交表单数据
<form action="/dy/html/getpost" method="post"> Name: <input type="text" name="fname" value="Ståle Refsnes"><br> <button type="submit" >使用编码提交</button> <button type="submit" formenctype="text/plain">不使用编码提交</button> </form>