DOM_节点层次_Document类型

时间:2023-03-08 20:56:22

一、Document类型

nodeType: 9;

nodeName: ”#document”;

nodeValue: null;

parentValue: null;

ownerDocumet: null.

其他浏览器(除IE)可以访问Document的构造函数与原型;

所有浏览器 (包括IE8 +)访问 HTMLDocument 的构造函数与原型;

var html = document.documentElement;//<html>的引用——所有浏览器支持
var body = document.body;//<body>的引用——所有浏览器支持

二、查找元素 document.getElementById()  ||  documet.getElementByTagName   ||  documet.getElementByName

document.getElementById() —— 区分大小写,IE8及更早不区分大小写。

特殊情况:<input>  <textarea>  <button>  <select>

<input type="text" name="text1" value="textVaile">
<div id="text1"></div>

IE7   通过document.getElementById(“text1”) 返回input

其他浏览器   通过document.getElementById(“text1”) 返回div

documet.getElementByTagName() —— 不区分大小写  返回一个HTMLCollection “动态”集合 类似NodeList;

<img src="a.gif" name="img">
var imgName = document.getElementByTagName("img").namedItem("img");

documet.getElementByName() —— 返回一个HTMLCollection “动态”集合 类似NodeList;

其他HTMLCollection 对象:

document.anchors——所有带name的<a>元素

document.images     document.forms     document.links

三、检测浏览器支持给定名称和版本的功能

var hasCss2 = document.implementation.hasFeature("CSS","2.0")