HTML DOM 輸入提交 formAction 屬性


HTML DOM 提交 formAction 屬性用於設定或獲取該表單的 formaction 屬性值。formaction 屬性指定單擊提交按鈕後要向其傳送資料的 URL。formAction 屬性值將覆蓋與 <form> 元素關聯的 action 屬性值。

語法

以下為語法 −

設定 formAction 屬性 −

submitObject.formAction = URL

其中,該 URL 可以是絕對 URL 也可以是相對 URL。

示例

我們來看一個提交 formAction 屬性的示例 −

<!DOCTYPE html>
<html>
<body>
<h1>Submit formAction Property</h1>
<form id="FORM_1" style="border:solid 2px green;padding:2px">
UserName: <input type="text" id="USR"> <br>
Location: <input type="text" id=“Loc”> <br><br>
<input type="submit" id="SUBMIT1" formaction="/New_page.php">
</form>
<p>Change the formAction attribute value to /Sample_page.php by clicking the below
button</p>
<button onclick="formActChange()">CHANGE</button>
<p id="Sample"></p>
<script>
   function formActChange() {
      document.getElementById("SUBMIT1").formAction="/Sample_page.php";
      document.getElementById("Sample").innerHTML = "The formaction attribute value is
      now 'Sample_page.php'";
   }
</script>
</body>
</html>

輸出

這將產生以下輸出 −

單擊 CHANGE 按鈕 −

更新於: 18-Jun-2020

90 次觀看

開啟您的 職業生涯

透過完成課程獲得認證

開始
廣告
© . All rights reserved.