DOM 对象

DOM  ==  document object model
 
document 对象是唯一同时属于  BOM 和 DOM  的
 
rows 是一种DOM集合,不是数组,所以没有sort() 函数。
 
NodeList   NamedNodeMap :
 
 
document.all  ==  document.getElementByTagName("*");   取得document中所有元素
 
ie6 在使用getElementByName() 和 getElementById() 时都会同时匹配 id 和 name 属性,要注意
 
ie 在使用 setAttribute()  有可能出错
所以尽可能使用  img.src 形式取代 img.getAttribute("src")   
 
Dom对象是host object,host 对象在ie8以及之前版本是通过COM实现的,而不是JScript
所以document.createElement 等Dom 方法是COM 对象的实例,因此typeof document.createElement 返回 object
 
每一个node节点都有自己的ownerDocument属性,如果将不同ownerDocument属性append到结构中会产生错误,需要使用importNode()方法。
 
注意直接定义在node上的属性,在标准浏览器和ie9,10中用getAttribute取不到,得到的结果是null
比如div.aa = 10,用div.getAttribute('aa')得到的是null,需要用div.aa或者div['aa']这样来取
 
 
 
Nodelist是类数组对象,但不是Array的实例( 转化为数组的话[].slice.call(eleList) ),当然用不了array的方法啦,同时它是动态更新的,实时变化的
function convertToArray(nodes)  {
    var array = null;
    try {
        array = Array.prototype.slice.call(nodes, 0); //non-IE and IE9+,throw an error because a NodeList is implemented as a COM object and thus cannot be used where a JScript object is necessary
    } 
    catch (ex)  {
        array = new Array();
        for (var i=0, len=nodes.length; i < len; i++)  {
            array.push(nodes[i]); 
        } 
    }
    return array; 
}
 
 
Dom把页面转化为层次节点结构的地图
Html或者xml的每一个部分都是一种包含不同数据的节点
通过这种树状结构来表示document,可以让开发者获得节点中的内容和修改它的结构
 
DOM Level 1 became a W3C recommendation in October 1998. It consisted of two modules(Dom core and Dom HTML interface):
the DOM Core, which provided a way to map the structure of an XML-based document to allow for easy access to and manipulation of any part of a document, and the DOM HTML, which extended the DOM Core by adding HTML-specific objects and methods.
 
Dom 2 added support for mouse and user-interface events (long supported by DHTML), ranges, traversals (methods to iterate over a DOM document), and support for Cascading Style Sheets (CSS) through object interfaces. The original DOM Core introduced in Level 1 was also extended to include support for XML namespaces.
 
- ➤ DOM Views — Describes interfaces to keep track of the various views of a document (the document before and after CSS styling, for example)
 
- ➤ DOM Events — Describes interfaces for events and event handling
 
- ➤ DOM Style — Describes interfaces to deal with CSS-based styling of elements
 
- ➤ DOM Traversal and Range — Describes interfaces to traverse and manipulate a document tree
 
 
DOM Level 3 further extends the DOM with the introduction of methods to load and save documents in a uniform way (contained in a new module called DOM Load and Save) and methods to validate a document (DOM Validation). In Level 3, the DOM Core is extended to support all of XML 1.0, including XML Infoset, XPath, and XML Base.
 
原文地址:https://www.cnblogs.com/chuangweili/p/5159769.html