HTML DOM 輸入提交形式方法屬性
HTML DOM 輸入提交形式方法屬性用於設定或返回一個提交按鈕的 formMethod 特性值。這指定在將表單資料傳送到伺服器時需要使用哪種 HTTP 方法。formMethod 特性值會覆蓋與 <form>元素關聯的方法特性值。它在 HTML5 中被引入,用於帶 submit 型別的輸入元素。
語法
以下是語法 −
設定 formMethod 屬性 −
submitObject.formMethod = get|post
這裡,get 是預設方法,用作 URL 的附錄。例如:URL?name=value & name=value。它通常不安全,可用於非私密資料。
使用者可以透過檢視 url 字串看到所傳送的資料。第二種方法,post作為 HTTP post 交易傳送資料,通常是安全的。由於在向伺服器傳送資料時任何人無法檢視資料,因此 post 方法不像 get 方法那樣有任何大小限制。
示例
讓我們看一個 Submit formMethod 屬性的示例 −
<!DOCTYPE html>
<html>
<body>
<h1>Submit formMethod property</h1>
<form id="FORM_1" action="/Sample.php" 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" formmethod="post">
</form>
<p>Set the formMethod attribute value of the above submit button inside the form to get
by clicking the below button</p>
<button onclick="changeMethod()">CHANGE</button>
<p id="Sample"></p>
<script>
function changeMethod() {
document.getElementById("SUBMIT1").formMethod = "get";
document.getElementById("Sample").innerHTML = "The formaction attribute value has been changed from post to get";
}
</script>
</body>
</html>輸出
這將產生以下輸出 −

點選 CHANGE 按鈕 −

廣告
資料結構
網路
RDBMS
作業系統
Java
iOS
HTML
CSS
安卓
Python
C 程式設計
C++
C#
MongoDB
MySQL
Javascript
PHP