<!DOCTYPE html>
<html>
<body>
<form action="/demo/action_page.php" target="_blank">
First name: <input type="text" name="fname" value="Bill"><br>
Last name: <input type="text" name="lname" value="Gates"><br><br>
<button id="myBtn" formmethod="get" type="submit">提交</button>
</form>
<p>单击下面的两个按钮可更改上面表单中提交按钮的 formmethod。</p>
<button onclick="setGet()">GET</button>
<button onclick="setPost()">POST</button>
<p id="demo"></p>
<script>
function setGet() {
document.getElementById("myBtn").formMethod = "GET";
document.getElementById("demo").innerHTML = "该 formaction 现在是 'GET'。";
}
function setPost() {
document.getElementById("myBtn").formMethod = "POST";
document.getElementById("demo").innerHTML = "该 formaction 现在是 'POST'。";
}
</script>
</body>
</html>