<html>
<body>
<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 />
<script type="text/javascript">
var x=document.getElementById("myForm");
for (var i=0;i<x.length;i++)
{
document.write(x.elements[i].value);
document.write("<br />");
}
for (var i=0;i<x.length;i++)
{
document.write(x.elements[i].type);
document.write("<br />");
}
</script>
</p>
</body>
</html>
Form 对象中 elements[] 的应用
最新推荐文章于 2018-07-30 09:18:27 发布