《JS高程(3)》DOM节点层次Document类型-第10章笔记(12)

来源:互联网 发布:列宾美院知乎 编辑:程序博客网 时间:2024/06/05 04:41

JavaScript通过Document类型表示文档。在浏览器中,document对象是HTMLDocument(继承自Document类型)的一个实例,表示整个HTML页面。document对象是window对象的一个属性,因此可以将其作为全局对象来访访问。
节点特征:

nodeType的值: 9 nodeName的值: “#document” nodeValue的值: null parentNode的值: null owenrDocument的值: null 子节点可能是: DocumentType(最多一个)、Element(最多一个)、ProcessingInstruction或Comment

通过Document可以取得与页面相关的信息,还能操作页面的外观和底层结构。

文档子节点

访问方式:documentElement、childNodes

documentElement 取得< html> document.body 取得< body> document.doctype 取得(个浏览器支持不一致) document.title 取得< title> document.URL 取得完整的URL document.domain 取得域名 document.referrer 取得来源页面的URL document.getElementById 取得特定的ID的元素 document.getElementByTagName 取得特定的标签名的元素 document.getElementByName 取得给定name特性的元素 document.anchors 取得带有name特性的< a>元素 document.forms 取得所有< form>元素,与document.getElementByTagName(“form”)得到的结果相同 document.images 取得所有< img>元素,与document.getElementByTagName(“img”)得到的结果相同 document.links 取得带有herf特性的< a>元素

文档写入

方法 参数 功能 write() 一个参数,写入到输出流中的文本 向页面中动态地加入文本内容 writeln() 一个参数,写入到输出流中的文本在末尾添加换行符(\n) 向页面中动态地加入文本内容 open() 打开页面的输出流 close() 关闭页面的输出流
0 0