javascript.2-常用元素属性

childNodes:获取一个元素下所有的子元素,返回一个数组

nodeType:返回值有12中可取值,其中有用的有,元素节点:1,属性节点:2,文本节点:3

nodeValue:文本节点值,假设一个<p id="p1">this is p</p>标签,想获取p中的"this is p"使用document.getElementById("p1").nodeValue返回值是null,因为这段文本相当于是p标签的第一个子节点的值,那么document.getElementById("p1").childNodes[0].nodeValue才可以返回正确的文本。

    childNodes[0]等同于firstChild方法,比如:document.getElementById("p1").firstChild.nodeValue

    childNodes[node.childNodes.length-1] 等同于lastChild方法

posted on 2017-09-04 20:56  kaka_79  阅读(118)  评论(0)    收藏  举报

导航