Form method 屬性

定義和用法
method 屬性可設(shè)置或者返回表單 method 屬性值。
method 屬性制訂了如何發(fā)送表單數(shù)據(jù) (表單數(shù)據(jù)提交地址在action屬性中指定)。
語法
formObject.method=value
method 屬性可以是以下值:
值 | 描述 |
---|---|
get | 在 URL 中添加表單數(shù)據(jù): URL?name=value&name=value (默認(rèn)) |
post | 使用 http post方法提交表單數(shù)據(jù) |
瀏覽器支持
所有主要瀏覽器都支持 method 屬性
注意: Internet Explorer如果沒有定義 method 屬性返回 "get"(默認(rèn)),其他瀏覽器無返回值。
實例
實例
返回表單數(shù)據(jù)發(fā)送方法:
<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>
以上實例輸出結(jié)果:
get
嘗試一下 ?

更多建議: