PHP8.1.21版本已发布
vue8.1.21版本已发布
jquery8.1.21版本已发布

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

PHPz
PHPz 转载
2023-08-22 08:53:22 951浏览

在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,如有侵犯,请联系admin@php.cn删除