HTML <button> formmethod 屬性
示例
一個包含兩個提交按鈕的表單。第一個提交按鈕使用 method="get" 提交表單資料,第二個提交按鈕使用 method="post" 提交表單資料。
<form action="/action_page.php" method="get">
<label for="fname">名:</label>
<input type="text" id="fname" name="fname"><br><br>
<label for="lname">姓氏:</label>
<input type="text" id="lname" name="lname"><br><br>
<button type="submit">提交</button>
<button type="submit" formmethod="post">使用 POST 提交</button>
</form>
自己動手試一試 »
定義和用法
formmethod
屬性指定了傳送表單資料時要使用的 HTTP 方法。此屬性會覆蓋表單的 method
屬性。
formmethod
屬性僅用於 type="submit"
的按鈕。
表單資料可以作為 URL 變數(使用 method="get"
)傳送,也可以作為 HTTP POST 請求(使用 method="post"
)傳送。
關於“get”方法的注意事項
- 它將表單資料以名稱/值對的形式附加到 URL 中
- 它適用於使用者想要收藏結果的表單提交
- URL 中可以放置的資料量有限(因瀏覽器而異),因此,您不能確定所有表單資料都能正確傳輸
- 切勿使用“get”方法傳遞敏感資訊!(密碼或其他敏感資訊將在瀏覽器的位址列中可見)
關於“post”方法的注意事項
- 它將表單資料作為 HTTP post 事務傳送
- 使用“post”方法的表單提交無法被收藏
- 它比“get”更健壯和安全
- 它沒有大小限制
瀏覽器支援
表格中的數字表示完全支援該屬性的第一個瀏覽器版本。
Attribute | |||||
---|---|---|---|---|---|
formmethod | 9.0 | 10.0 | 4.0 | 5.1 | 15.0 |
語法
<button type="submit" formmethod="get|post">
屬性值
值 | 描述 |
---|---|
get | 將表單資料附加到 URL:URL?name=value&name=value |
post | 將表單資料作為 HTTP post 事務傳送 |
❮ HTML <button> 標籤