HTML DOM 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
嘗試一下»
Form對象