天天看點

HTML <button> formmethod 屬性

HTML <button> 标簽

執行個體

帶有兩個送出按鈕的表單,第一個送出按鈕使用 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>

浏覽器支援

HTML &lt;button&gt; formmethod 屬性
HTML &lt;button&gt; formmethod 屬性
HTML &lt;button&gt; formmethod 屬性
HTML &lt;button&gt; formmethod 屬性
HTML &lt;button&gt; formmethod 屬性

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)