Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // 返回元素e 的纯文本内容,递归进入其子元素
- // 该方法的效果类似于textContent 属性
- function textContent(e){
- var child, type, s = ""; // s 保存所有子节点的文本
- for(child = e.firstChild; child != null; child = child.nextSibling){
- type = child.nodeType;
- if(type === 3 || type === 4) // Text 和CDATASection 节点
- s += child.nodeValue;
- else if(type === 1) // 递归Element 节点
- s += textContent(child);
- }
- return s;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement