document对象详解

  • Post author:
  • Post category:其他


在浏览器中,与用户进行数据交换都是通过客户端的

javascript

代码来实现的,而完成这些交互工作大多数是

document

对象及其部件进行的,因此

document

对象是一个比较重要的对象。

document对象概述


document

对象是文档的根节点,

window.document

属性就指向这个对象。也就是说,只要浏览器开始载入

HTML

文档,这个对象就开始存在了,可以直接调用。


document.childNodes

属性返回该对象的所有子节点。对于HTML文档来说,

document

对象一般有两个子节点。

第一个子节点是

document.doctype

,表示文档类型节点(DocumentType)。对于HTML5文档来说,该节点就代表

<!DOCTYPE html>

第二个子节点是

document.documentElement

,表示元素节点(Element),代表:

<html lang="en">。

document 对象的属性


document

对象主要有如下属性:

</

属性 说明
document.title 设置文档标题等价于HTML的<title>标签
document.bgColor 设置页面背景色
document.linkColor 未点击过的链接颜色
document.alinkColor 激活链接(焦点在此链接上)的颜色
document.fgColor 设置前景色(文本颜色)
document.vlinkColor 已点击过的链接颜色



版权声明:本文为Zhi_19950628原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。