HTML formmethod 屬性用於定義用於在提交表單時發送表單數據的 HTTP 方法。 GET 和 POST 是兩種眾所周知的 HTTP 方法。該屬性覆蓋了 <form> 元素的 method 屬性的特性。
支持的標簽:
用法:
<element formmethod="get|post">
值:
- get:在 GET 方法中,提交表單後,表單值將在新瀏覽器選項卡的地址欄中可見。它的大小限製為大約 3000 個字符。它僅對非安全數據有用,對敏感信息無效。
- post:在 post 方法中,提交表單後,表單值在新瀏覽器選項卡的地址欄中將不可見,因為它在 GET 方法中可見。它將表單數據附加到 HTTP 請求的正文中。它沒有大小限製。此方法不支持為結果添加書簽。
範例1:下麵的代碼演示了在 HTML <input type="submit"> 控件中使用 formmethod 屬性。請參閱下麵給出的輸出以獲得更好的理解。注意點擊“Submit normally”和“使用POST方法提交”的新網頁的地址欄。兩者都不同,一個顯示用戶詳細信息,後者隱藏所有用戶詳細信息。
HTML
<!DOCTYPE html>
<html>
<head>
<title>
HTML formmethod Attribute
</title>
</head>
<body style="text-align:center;">
<h1 style="color:green;">
GeeksforGeeks
</h1>
<h3>HTML formmethod Attribute</h3>
<form action="#"
id="users"
action="#"
method="GET"
target="_blank">
User_id:
<input type="email"
name="email"
placeholder="Emter Email Id">
<br>
<br> Password:
<input type="password"
name="pword"
placeholder="Enter Password">
<br>
<br>
<input type="submit" value="Submit normally">
<input type="submit" formaction="#"
value="submit using POST method"
formmethod="post">
</form>
</body>
</html>
輸出:
範例2:下麵的示例演示了使用按鈕元素的 HTML formmethod="get" 屬性。它將用戶條目提交到 “getDetail.php” PHP 文件。當用戶單擊“使用 get 方法提交”時,值將提交到 PHP 文件,注意下麵輸出中的地址欄。
HTML
<!DOCTYPE html>
<html>
<body style="text-align:center;">
<h1 style="color:green;">
GeeksforGeeks
</h1>
<h3>HTML formmethod get Attribute</h3>
<form action="getDetail.php">
User name:
<input name="username"
placeholder="Enter username">
<br>
<br> Profession:
<input
name="profession"
placeholder="Enter profession">
<br>
<br>
<button formmethod="get">
Submit using get method
</button>
</form>
</body>
</html>
輸出:
支持的瀏覽器:
- 穀歌瀏覽器 9.0
- Internet Explorer 10.0
- Firefox 4.0
- Safari 5.1
- Opera 10.6
相關用法
- HTML <button> formmethod屬性用法及代碼示例
- HTML input formmethod用法及代碼示例
- HTML Input Submit formMethod用法及代碼示例
- HTML Input Image formMethod用法及代碼示例
- HTML Button formMethod用法及代碼示例
- HTML <html> xmlns屬性用法及代碼示例
- HTML scoped屬性用法及代碼示例
- HTML <th> valign屬性用法及代碼示例
- HTML <col> align屬性用法及代碼示例
- HTML poster屬性用法及代碼示例
- HTML <area> target屬性用法及代碼示例
- HTML <select> autocomplete屬性用法及代碼示例
- HTML <td> abbr屬性用法及代碼示例
- HTML readonly屬性用法及代碼示例
- HTML required屬性用法及代碼示例
- HTML oncopy屬性用法及代碼示例
- HTML oncut屬性用法及代碼示例
- HTML enctype屬性用法及代碼示例
- HTML pattern屬性用法及代碼示例
- HTML multiple屬性用法及代碼示例
- HTML placeholder屬性用法及代碼示例
- HTML lang屬性用法及代碼示例
注:本文由純淨天空篩選整理自ManasChhabra2大神的英文原創作品 HTML formmethod Attribute。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。