当前位置: 首页 > 网络学院 > 客户端脚本教程 > HTML DOM > DOM Document 对象
The Document object represents the entire HTML document and can be used to access all elements in a page.
Document对象代表着整个HTML文档并可以用来访问所有页面中的元素。
IE: Internet Explorer, F: Firefox, N: Netscape, W3C: World Wide Web Consortium (Internet Standard), D: Deprecated.
Collection 集合 | Description 描述 | IE | F | N | W3C |
---|---|---|---|---|---|
anchors[] | Returns a reference to all Anchor objects in the document 罗列document中所有Anchor对象的参考 | 3 | 1 | 2 | Yes |
applets[] | Returns a reference to all Applet objects in the document 返回在文档中所有Applet对象的参考 | 4 | 1 | 3 | Yes |
attributes[] | - | 1 | 6 | No | |
childNodes[] | 5 | 1 | 6 | No | |
embeds[] | Returns a reference to all embedded objects in the document 返回在文档里所有嵌入对象的参考 | 4 | 1 | 3 | No |
forms[] | Returns a reference to all Form objects in the document 罗列document中所有表单对象的参考 | 3 | 1 | 2 | Yes |
images[] | Returns a reference to all Image objects in the document 罗列document中所有image对象的参考 | 4 | 1 | 3 | Yes |
links[] | Returns a reference to all Link objects in the document 返回在文档中所有link对象的参考 | 3 | 1 | 2 | Yes |
plugins[] | - | 1 | 6 | No | |
stylesheets[] | 5 | 1 | 6 | No |
Property 属性 | Description 描述 | IE | F | N | W3C |
---|---|---|---|---|---|
alinkColor | Sets or returns the color of the active links in the document 设置或返回在文档中活动连接的颜色 | 3 | 1 | 2 | D |
bgColor | Sets or returns the background-color of the document 设置或返回文档背景颜色 | 3 | 1 | 2 | D |
body | Specifies the beginning and end of the document body 指定文档body的开头和结尾 | 5 | 1 | 6 | Yes |
cookie | Sets or returns all cookies associated with the document 通过document设置或返回所有有关文档的cookies | 3 | 1 | 2 | Yes |
documentElement | Returns a reference to the root node of the document 返回文档根部节点的参考 | 5 | 1 | 6 | No |
domain | Returns the document server's domain name 返回文档的服务器域名 | 4 | 1 | 3 | Yes |
fgColor | Sets or returns the text-color of the document 设置或返回文档的文字颜色 | 3 | 1 | 2 | D |
lastModified | Returns the date and time the document was last modified 返回文挡最后修改的日期 | 3 | 1 | 2 | No |
linkColor | Sets or returns the color of the links in the document 设置或返回文档中连接的颜色 | 3 | 1 | 2 | D |
referrer | Returns the URL of the document that loaded the current document 返回被直接加载的文档URL | 3 | 1 | 2 | Yes |
title | Returns the title of the document 返回文档的标题 | 3 | 1 | 2 | Yes |
URL | Returns the URL of the current document 返回当前文档的URL | 4 | 1 | 3 | Yes |
vlinkColor | Sets or returns the color of the visited links in the document 设置或返回文档中访问过连接的颜色 | 3 | 1 | 2 | D |
Method 方法 | Description 描述 | IE | F | N | W3C |
---|---|---|---|---|---|
clear() | Clears all elements in the document 清空所有文档中的元素 | - | 1 | 2 | No |
close() | Closes the output stream and displays the sent data 关闭输出流以及发送数据的显示 | 3 | 1 | 2 | Yes |
createAttribute("name") | Creates an attribute with a specified name 建立指定name的属性 | 6 | 1 | 6 | No |
createElement("tag") | Creates an element 建立元素 | 5 | 1 | 6 | Yes |
createTextNode("txt") | Creates a text string 建立文字串 | 5 | 1 | 6 | Yes |
focus() | Gives the document focus 文档聚焦 | 5 | 1 | 6 | No |
getElementById() | Returns a reference to the first object with the specified ID 通过指定ID返回第一个符合对象的参考 | 5 | 1 | 6 | Yes |
getElementsByName() | Returns a collection of objects with the specified NAME 通过指定NAME返回符合的对象集合 | 5 | 1 | 6 | Yes |
getElementsByTagName("tag") | Returns a collection of objects with the specified TAGNAME 通过指定TAGNAME返回符合的对象 | 5 | 1 | 6 | No |
open() | Opens a document for writing 为写入打开一份文档 | 3 | 1 | 2 | Yes |
write() | Writes a text string to a document 在文档中写入文字串 | 3 | 1 | 2 | Yes |
writeln("str") | Writes a text string followed by a new line character to a document opened by open() 新行写入 | 3 | 1 | 2 | Yes |
Syntax: document.event_name="someJavaScriptCode"
Event 事件 | Description 描述 | IE | F | N | W3C |
---|---|---|---|---|---|
onClick | Executes some code when a Click event occurs 当点击事件发生的时候执行一些代码 | 5 | 1 | 6 | |
onDblClick | Executes some code when a Doubleclick event occurs 当双击事件发生的时候执行一些代码 | 5 | 1 | 6 | |
onFocus | Executes some code when a Focus event occurs 当聚焦事件发生的时候执行一些代码 | 5 | 1 | 6 | |
onKeyDown | Executes some code when a Keydown event occurs 当键按住事件发生时执行一些代码 | 5 | 1 | 6 | |
onKeyPress | Executes some code when a Keypress event occurs 当键按下事件发生就执行一些代码 | 5 | 1 | 6 | |
onKeyUp | Executes some code when a Keyup event occurs 当提键事件发生就执行代码 | 5 | 1 | 6 | |
onMouseDown | Executes some code when a Mousedown event occurs 当鼠标按住事件发生就执行代码 | 5 | 1 | 6 | |
onMouseMove | Executes some code when a Mousemove event occurs 当鼠标移动事件发生就执行代码 | 5 | 1 | 6 | |
onMouseOut | Executes some code when a Mouseout event occurs 当鼠标离开事件发生就执行一些代码 | 5 | 1 | 6 | |
onMouseOver | Executes some code when a Mouseover event occurs 当鼠标移到上方事件发生就执行代码 | 5 | 1 | 6 | |
onMouseUp | Executes some code when a Mouseup event occurs 到鼠标释放就执行代码 | 5 | 1 | 6 | |
onResize | Executes some code when a Resize event occurs 当改变大小事件发生就执行代码 | 5 | 1 | 6 |