HTML formaction 屬性
定義和用法
formaction
屬性指定當表單提交時,資料傳送到何處。此屬性將覆蓋表單的 action
屬性。
formaction
屬性僅用於 type="submit"
的 input/button。
適用範圍
formaction
屬性可用於以下元素:
元素 | Attribute |
---|---|
<button> | formaction |
<input> | formaction |
示例
按鈕示例
一個包含兩個提交按鈕的表單。第一個提交按鈕將表單資料提交到 "action_page.php",第二個提交到 "action_page2.php"
<form action="/action_page.php" method="get">
名:<input type="text" name="fname"><br>
姓:<input type="text" name="lname"><br>
<button type="submit">提交</button><br>
<button type="submit" formaction="/action_page2.php">提交到另一個頁面</button>
</form>
自己動手試一試 »
Input 示例
具有兩個提交按鈕的 HTML 表單,具有不同的操作
<form action="/action_page.php">
名:<input type="text" name="fname"><br>
姓:<input type="text" name="lname"><br>
<input type="submit" value="提交"><br>
<input type="submit" formaction="/action_page2.php" value="提交到另一個頁面">
</form>
自己動手試一試 »
瀏覽器支援
formaction
屬性對每個元素的瀏覽器支援如下:
元素 | |||||
---|---|---|---|---|---|
button | 9.0 | 10.0 | 4.0 | 5.1 | 10.6 |
input | 9.0 | 10.0 | 4.0 | 5.1 | 10.6 |