window -- document用于表现HTML页面当前窗体的内容javascript
下面内容的不建议使用css
因为document表明HTML文档的内容,所以能够经过它表示文档中加载的一些元素,这些元素所有经过集合访问。html
能够使用数字或名称索引页面中的元素集合,每一个元素的属性都变成了集合中相应对象的属性。java
<form name="form1"><a href="http://www.dreamdu.com/xhtml/" name="a1">xhtml</a></form> <form name="form2"><a href="http://www.dreamdu.com/css/" name="a2">css</a></form> <form name="form3"><a href="http://www.dreamdu.com/javascript/" name="a3">javascript</a></form> <input type="button" value="显示第二个表单的名称" onclick="alert(document.forms[1].name)" /> <input type="button" value="显示第二个表单的名称第二种方法" onclick="alert(document.forms['form2'].name)" /> <input type="button" value="显示第三个连接的名称" onclick="alert(document.links[2].name)" /> <input type="button" value="显示第三个连接的名称第二种方法" onclick="alert(document.links['a3'].name)" /> <input type="button" value="显示第三个连接href属性的值" onclick="alert(document.links[2].href)" />
表示第二个表单的方法:document.forms[1]或document.forms["form2"]浏览器
表示第三个连接的方法:document.links[2]或document.links["a3"]cookie
表示第三个连接href属性的方法:document.links[2].hrefapp