HTML button formmethod 屬性
實例
帶有兩個提交按鈕的表單,第一個提交按鈕使用method="get" 提交表單數據,第二個提交按鈕使用method="post" 提交表單數據:
<form action="demo_form.html" method="get">
First name: <input type="text" name="fname"><br>
Last name: <input type="text" name="lname"><br>
<button type="submit">提交</button>
<button type="submit" formmethod="post" formaction="demo_post.html">
使用 POST 提交</button>
</form>
First name: <input type="text" name="fname"><br>
Last name: <input type="text" name="lname"><br>
<button type="submit">提交</button>
<button type="submit" formmethod="post" formaction="demo_post.html">
使用 POST 提交</button>
</form>
嘗試一下»
瀏覽器支持
Internet Explorer 10, Firefox, Opera, Chrome, 和Safari 支持formmethod 屬性。
注意: Internet Explorer 9及更早IE版本不支持formmethod屬性。
定義和用法
formmethod 屬性制定發送表單數據使用的HTTP 方法。 formmethod屬性覆蓋form元素的method屬性。
formmethod 屬性需與type="submit" 配合使用。
可以通過以下方式發送form-data :
- 以URL 變量(使用method="get") 的形式來發送
- 以HTTP post (使用method="post") 的形式來發送
使用"get" 方法:
- 表單數據在URL中以name/value 對出現。
- get傳送的數據量較小,不能大於2KB,這主要是因為受URL長度限制。
- 不要使用"get" 方法傳送敏感信息! (密碼或者敏感信息會出現在瀏覽器的地址欄中)
使用"post" 方法:
- 以HTTP post 形式發送表單數據。
- 比"get" 方法更強大更安全。
- 沒有大小限制
HTML 4.01 與HTML5之間的差異
formmethod 屬性是HTML 5 中的新屬性。
語法
<button type="submit" formmethod="get|post">
屬性值
值 | 描述 |
---|---|
get | 向 URL 追加表单数据(form-data):URL?name=value&name=value |
post | 以 HTTP post 事务的形式发送表单数据(form-data) |
HTML <button>標籤