PHP前端开发

在HTML中,enctype='multipart/form-data'是什么意思?

百变鹏仔 4周前 (09-22) #HTML
文章标签 enctype

使用 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>

登录并显示结果 −