为什么 formaction 属性不适用于
我们可以让 formaction 属性在 <form> 标签之外工作。formaction 属性用于为一个表单指定多个提交 URL。提交表单时,web 浏览器首先检查是否有 formaction 属性。
如果没有 formaction,web 浏览器会继续查找表单元素上的 action 属性。
示例
下面是一个带三个不同提交按钮的 formaction 属性的示例 −
<!DOCTYPE html> <html> <head> <title>HTML formaction attribute</title> </head> <body> <form method="post"> <input type = "text" name="name"/><br> <button type = "submit" formaction = "btn1.php">Button1</button> <button type = "submit" formaction = "btn2.php">Button2</button> <button type = "submit" formaction = "btn3.php">Button3</button> </form> </body> </html>
是的,formaction 属性不适用于 form 元素之外,但你仍然可以用以下方法让它们正常工作 −

示例
您可以使用关联的表单 id 值轻松放置按钮并在表单外部使用 formaction 属性。
<!DOCTYPE html> <html> <head> <title>HTML formaction attribute</title> </head> <body> <form method="post" id="newForm"> <input type="text" name="name"/> </form> <button type="submit" formaction="btn1.php" form="newForm">Button1</button> <button type="submit" formaction="btn2.php" form="newForm">Button2</button> <button type="submit" formaction="btn3.php" form="newForm">Button3</button> </body> </html>
广告
数据结构
网络
RDBMS
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP