DOM是一个针对html和XML文档的一个API,主要描绘了一个层次化的节点树
节点关系:childNodes,parentNode,firstChild,lastChild,nextSibling
操作节点:appendChild,insertBefore,replaceChild,removeChild,cloneNode
Element类型
常用标准特性:(可以设置可以获取)
1)element.id,title,lang,dir(语言的方向,从左至右ltr,从右至左rtl),className……特别的,
自定义属性用点方法失效,事件处理程序(以属性形式存在的时候)和style属性在点方法和
get/setAttribute方法上有不同
2)相对应的另一种设置或者获取特性(属性)的方法:getAttribute(),setAttribute(),
removeAttribute()
3)attributes属性,是Element类型的专属属性(其他类型的节点无法使用),遍历元素可以用。
4)document.createElement()
Text类型
常用操作文本的方法:
1) appendData()
2) deleteData()
3) insertData(offset,text) offset指定位置
4) replaceData(offset,count,text) count个数
5) splitText(offset)从指定位置将文本分成两部分,返回从切的位置到剩下的位置
6) substringData(offset,count)
7) document.createTextNode()
来源: http://www.bubuko.com/infodetail-1966034.html