HTML 表單方法屬性


HTML 表單 method 屬性定義了傳送表單資料的方式,即用作 URL 變數傳送還是用作 HTTP post 交易傳送。

語法

以下是語法 −

<form method=”get | post”></form>

此處 get 將表單資料作為 URL 變數傳送,而 post 將表單資料作為 HTTP post 交易傳送。

我們來看一個 HTML 表單 method 屬性的示例−

示例

 即時演示

<!DOCTYPE html>
<html>
<style>
   body {
      color: #000;
      height: 100vh;
      background: linear-gradient(62deg, #FBAB7E 0%, #F7CE68 100%) no-repeat;
      text-align: center;
   }
   input {
      width: 315px;
      display: block;
      margin: 1rem auto;
      border: 2px solid #fff;
      padding: 8px;
      background: transparent;
      border-radius: 20px;
      outline: none;
   }
   ::placeholder {
      color: #000;
   }
   .btn {
      background: #db133a;
      border: none;
      height: 2rem;
      border-radius: 20px;
      width: 330px;
      display: block;
      color: #fff;
      outline: none;
      cursor: pointer;
      margin: 1rem auto;
   }
</style>
<body>
<h1>HTML Form method Attribute Demo</h1>
<form action="/action_page.php" method="get">
<input type="text" name="firstname" placeholder="Enter First Name">
<input type="text" name="lastname" placeholder="Enter Last Name">
<input type="submit" value="SUBMIT" class="btn">
</form>
</body>
</html>

輸出

輸入表單詳細資訊,然後使用“提交”按鈕提交表單,以觀察 method 屬性如何工作。

更新於:27-Sep-2019

297 次瀏覽

開啟您的 職業生涯

完成課程後獲得認證

開始
廣告
© . All rights reserved.