Form method 屬性

定義和用法
method 屬性可設置或者返回表單 method 屬性值。
method 屬性制訂了如何發送表單數據 (表單數據提交地址在action屬性中指定)。
語法
formObject.method=value
method 屬性可以是以下值:
值 | 描述 |
---|---|
get | 在 URL 中添加表單數據: URL?name=value&name=value (默認) |
post | 使用 http post方法提交表單數據 |
流覽器支持
所有主要流覽器都支持 method 屬性
注意: Internet Explorer如果沒有定義 method 屬性返回 "get"(默認),其他流覽器無返回值。
實例
實例
返回表單數據發送方法:
<html>
<body>
<form id="frm1" action="form_action.html" method="get">
First name: <input type="text" name="fname" value="Donald"><br>
Last name: <input type="text" name="lname" value="Duck"><br>
<input type="submit" value="Submit">
</form>
<script>
document.write(document.getElementById("frm1").method);
</script>
</body>
</html>
<body>
<form id="frm1" action="form_action.html" method="get">
First name: <input type="text" name="fname" value="Donald"><br>
Last name: <input type="text" name="lname" value="Duck"><br>
<input type="submit" value="Submit">
</form>
<script>
document.write(document.getElementById("frm1").method);
</script>
</body>
</html>
以上實例輸出結果:
get
