
使用 enctype 属性来指定浏览器在将数据发送到服务器之前如何对数据进行编码。可能的值有 -
application/x-www-form-urlencoded − 这是大多数表单在简单场景中使用的标准方法。
mutlipart/form-data − 这用于在表单中上传二进制数据,如图像、Word文件等。
现在让我们来看一个例子−
立即学习“前端免费学习笔记(深入)”;
<!DOCTYPE html>
<html>
<head>
<title>HTML enctype attribute</title>
<style>
form {
width: 70%;
margin: 0 auto;
text-align: center;
}
* {
padding: 2px;
margin: 5px;
}
input[type="button"] {
border-radius: 10px;
}
</style>
</head>
<body>
<h1>Login</h1>
<form enctype="multipart/form-data" action="" method="post">
<fieldset>
<legend>Enter the login details</legend>
<label for="EmailSelect">Email Id:
<input type="email" id="EmailSelect">
<input type="button" onclick="getUserEmail('abc')" value="abc">
<input type="button" onclick="getUserEmail('pqr')" value="pqr"><br>
<input type="button" onclick="login()" value="Login">
</label>
<div id="divDisplay"></div>
</fieldset>
</form>
<script>
var divDisplay = document.getElementById("divDisplay");
var inputEmail = document.getElementById("EmailSelect");
function getUserEmail(userName) {
if (userName === 'abc')
inputEmail.value = 'abc@MNC.com';
else
inputEmail.value = 'pqr@MNC.com';
}
function login() {
if (inputEmail.value !== '')
divDisplay.textContent = 'Successful Login. Hello ' + inputEmail.value.split("@")[0];
else
divDisplay.textContent = 'Enter Email Id';
}
</script>
</body>
</html>
登录并显示结果 −
以上就是在HTML中,enctype='multipart/form-data'是什么意思?的详细内容,更多请关注php中文网其它相关文章!
HTML怎么学习?HTML怎么入门?HTML在哪学?HTML怎么学才快?不用担心,这里为大家提供了HTML速学教程(入门课程),有需要的小伙伴保存下载就能学习啦!
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号