在HTML中,enctype=’multipart/form
使用 enctype 属性来指定浏览器在将数据发送到服务器之前如何对数据进行编码。可能的值有 –
-
application/x-www-form-urlencoded − 这是大多数表单在简单场景中使用的标准方法。
-
mutlipart/form-data − 这用于在表单中上传二进制数据,如图像、Word文件等。
Example
现在让我们来看一个例子−
<!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’是什么意思?的详细内容,更多请关注双恒网络其它相关文章!
声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。