2.document.forms
例 2.1(FormActionSubmitIEFF.html)
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8"/>
<TITLE></TITLE>
<SCRIPT LANGUAGE="JavaScript">
/*
JavaScript syntax: - myObject.onclick = aHandler
HTML syntax: <A onClick="..."> <AREA onClick="..."> <HTMLTag onClick="..."> <INPUT onClick="...">
Form object (Object/HTML)
An object representing an HTML <FORM> tag.
*/
function clickH(actUrl)
{
/*Document.forms[] (Collection)
An array containing a list of all the forms in the document.*/
var fm = document.forms[0];
/*Form.action (Property)
A property that contains the submit action method for the <FORM>.
JavaScript syntax: - myForm.action
HTML syntax: <FORM ACTION="...">
*/
fm.action = actUrl;
/*Form.submit() (Method)
Invoke a form submit to the server.*/
fm.submit();
}
</SCRIPT>
</HEAD>
<BODY>
<FORM METHOD=POST>
<input name="name" type="text"/><br>
<input type="button" value="提交到第一个地址" onClick="clickH('1.htm?k=b')"/>
<input type="button" value="提交到第二个地址" onClick="clickH('2.htm')"/>
</FORM>
</BODY>
</HTML>
例 2.2(FormObjectReferenceIEFF.html)
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8"/>
<SCRIPT LANGUAGE="JavaScript">
<!--
function test()
{
var txt1 = document.forms[0].elements[0].value
var txt2 = document.regForm.username.value
var psw1 = document.forms[0].elements[1].value
var psw2 = regForm.psw.value;
with(document)
{
write("document.forms[0].elements[0].value-->"+txt1+"<br>")
write("document.regForm.username.value-->"+txt2+"<br>")
write("document.forms[0].elements[1].value-->"+psw1+"<br>")
write("regForm.psw.value-->"+psw2+"<br>")
}
}
更多内容请见原文,文章转载自:https://blog.csdn.net/qq_43650923/article/details/103046648