javascript当中document.forms的用法
2021/12/8 22:18:57
本文主要是介绍javascript当中document.forms的用法,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
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
这篇关于javascript当中document.forms的用法的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-11-15JavaMailSender是什么,怎么使用?-icode9专业技术文章分享
- 2024-11-15JWT 用户校验学习:从入门到实践
- 2024-11-15Nest学习:新手入门全面指南
- 2024-11-15RestfulAPI学习:新手入门指南
- 2024-11-15Server Component学习:入门教程与实践指南
- 2024-11-15动态路由入门:新手必读指南
- 2024-11-15JWT 用户校验入门:轻松掌握JWT认证基础
- 2024-11-15Nest后端开发入门指南
- 2024-11-15Nest后端开发入门教程
- 2024-11-15RestfulAPI入门:新手快速上手指南