HTML 中的 enctype='multipart/form-data' 是什么意思?
htmlweb developmentfront end technology更新于 2024/6/6 14:36:17
使用 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 参考教程 - 该教程包含有关 html 的更多信息:https://www.cainiaomax.com/html/

