<html> <body id="myBody" class="myBody"> <form id="myForm"> Firstname: <input id="fname" type="text" value="Mickey" /> Lastname: <input id="lname" type="text" value="Mouse" /> <input id="sub" type="button" value="Submit" /> </form> <p>Get the value of all the elements in the form:<br /> <form id="myForm1" action="index.php" method="post" name="myForm1"> name: <input id="fname" type="text" value="Mickey" /> <input id="sub" type="button" value="Submit" onclick="changeAction()"/> </form> <form id="myForm2" action="index.php" method="post" name="myForm2"> name: <input id="fname" type="text" value="Mickey" /> <input id="sub" type="button" value="Submit" onclick="Submit1()"/> <input id="res" type="button" value="reset" onclick="reset1()"/> </form> </body> <script> //Form 对象的集合 //elements 集合可返回包含表单中所有元素的数组。 /*var x = document.getElementById('myForm'); for(var i=0;i<x.length;i++){ document.write(x.elements[i].value); document.write("<br />"); document.write(x.elements[i].type); document.write("<br />"); } //Form 对象的属性 //action 属性可设置或返回表单的 action 属性。 //action 属性定义了当表单被提交时数据被送往何处。 function changeAction(){ var x = document.getElementById("myForm1"); alert(x.action); //http://localhost/js/dom/index.php x.action = "index1.php"; alert(x.action); //http://localhost/js/dom/index1.php } //id 属性可设置或返回表单的 id var x = document.getElementsByTagName("form")[0]; alert(x.id); //myForm //length 属性可返回表单中元素的数目 var x = document.getElementById('myForm1'); alert(x.length); //2 //method 属性可设置或返回用于表单提交的 HTTP 方法 var x = document.getElementById('myForm1'); alert(x.method); //post //name 属性可设置或返回表单的名称 var x = document.getElementById('myForm1'); alert(x.name); //myForm1 //Form 对象的方法 //reset() 方法可把表单中的元素重置为它们的默认值。 function reset1(){ document.getElementById("myForm2").reset(); } */ //submit() 方法把表单数据提交到 Web 服务器。 function Submit1(){ document.getElementById("myForm2").submit(); } </script> </html>
Form 对象的集合
转载本文章为转载内容,我们尊重原作者对文章享有的著作权。如有内容错误或侵权问题,欢迎原作者联系我们进行内容更正或删除文章。
上一篇:随机变量数学期望的一个实例
下一篇:并排两个对象对不齐如何解决
提问和评论都可以,用心的回复会被更多人看到
评论
发布评论
相关文章
-
Odoo集合pdfjs实现在form表单上预览附件
Odoo集成pdfjs实现预览附件
字段 html HTML odoo -
Java8处理对象List集合之间的交集、并集、差集和去重
Java8处理对象List集合之间的交集、并集、差集和去重
交集 并集 去重 Stream 差集 -
form表单的对象
这个是关于表单,表单在HTML中是很重要的一个部分,关于表单的使用,里面的属性和方法不算
表单 对象 方法和属性 提交表单 数组 -
HTML DOM Form对象
前言: :http://www.w3cschool.cn/dom_obj_form.html 感谢,个人做积累记录学习! 正文: Form对象 代表一个
document form dom enctype 表单 -
获取form对象
new document 用户名: 密码:
html 提交表单 javascript 添加属性 php