首頁  >  文章  >  web前端  >  在HTML中,enctype='multipart/form-data'是什麼意思?

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

PHPz
PHPz轉載
2023-08-22 08:53:221440瀏覽

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

使用 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'是什麼意思?的詳細內容。更多資訊請關注PHP中文網其他相關文章!

陳述:
本文轉載於:tutorialspoint.com。如有侵權,請聯絡admin@php.cn刪除