HTML DOM Input Submit formEnctype 属性
htmlweb developmentfront end technology更新于 2024/5/28 10:20:17
HTML DOM Submit 的 formEnctype 属性用于设置或返回提交按钮的 formEnctype 属性值。该属性在 HTML5 中引入,用于提交类型的输入元素。它用于指定表单数据提交到服务器时应如何编码。
此属性仅在 method=”post” 属性时有效。formEnctype 属性值会覆盖与 <form> 元素关联的 enctype 属性值。
语法
以下是语法 −
设置 Submit formEnctype 属性 −
submitObject.enctype = encoding
此处,编码可以是 “application/x-www-form-urlencoded”,这意味着所有字符在发送前都会进行编码,这是默认编码。另一个是"multipart/form-data",它指定无需编码任何字符,用于将文件上传到服务器。第三个编码是"text/plain",它只会将空格转换为"+"符号,而不会进行其他编码。text/plain 编码不安全,因此不应使用。
示例
让我们来看一个关于 submit formEnctype 属性的示例。 −
<!DOCTYPE html>
<html>
<head>
<script>
function changeEnc() {
document.getElementById("SUBMIT1").formEnctype = "application/x-www-formurlencoded";
document.getElementById("Sample").innerHTML = "The formenctype attribute value is now 'application/x-www-form-urlencoded' ";
}
</script>
</head>
<body>
<h1>Submit formEnctype property example</h1>
<form id="FORM_1" action="/Sample.php" style="border:solid 2px green;padding:2px">
UserName: <input type="text" id="USR"> <br>
Location: <input type="text" id=“Loc”> <br><br>
<input type="submit" id="SUBMIT1" formenctype="multipart/form-data">
</form>
<br>
<button onclick="changeEnc()">CHANGE</button>
<p id="Sample"></p>
</body>
</html>
输出
这将产生以下输出 −

点击"更改"按钮 −

相关文章
有用资源
html 参考教程 - 该教程包含有关 html 的更多信息:https://www.cainiaomax.com/html/

