DOM.html:
<html>
<body>
<form name="Form1" id="Form1" name="Form2">
<input name="Input1" value="dddd" type="text"/>
<input name="Input2" value="ssss" type="texy"/>
</form>
<form name="Form2" id="Form2" name="Form2">
<input name="Input1" value="dddd" type="text"/>
<input name="Input2" value="ssss" type="texy"/>
</form>
<script>
document.write("Form1:"+document.forms[0].elements[0].value+"<br/>")
document.write("Form1:"+document.Form1.Input1.value+"</br>");
document.write("Form2:"+document.forms[1].name);
document.close();
</script>
</body>
</html>
通过document获取表单元素时的方法有两种,
1.通过frames--forms--elements访问
2.通过name值访问
window等同于self的作用,一般省略
Window.window等同于Window.self等同于window等同于self
另外document的属性常用的有两个forms,images,frames方法getElementById,getElementsByName等,注意必须是document的方法,见下图