如何在 HTML 中使用 formaction 属性?

htmlweb developmentfront end technology

假设您的表单中有两个提交按钮,并且您希望这两个按钮分别工作,那么 formaction 属性就会起作用。这两个按钮会将数据发送到不同的页面。formaction 属性会覆盖表单的 action 属性。

注意 减:Internet Explorer 9 及更早版本不支持 formaction 属性。

示例

您可以尝试运行以下代码,了解如何在 HTML 中使用 formaction  属性 −

<!DOCTYPE html>
<html>
   <head>
      <title>HTML formaction attribute</title>
   </head>

   <body>
      <form action = "/new1.php" method = "get">
         Student name: <input type = "text" name = "name"><br>
         Student Subject: <input type = "text" name = "subject"><br>
         <button type = "submit">Submit</button><br>
         <button type = "submit" formaction = "/new2.php">Another page</button>
      </form>
   </body>
</html>

相关文章


有用资源