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 |