Advertisement
Guest User

Untitled

a guest
Jun 26th, 2017
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.48 KB | None | 0 0
  1. // 返回元素e 的纯文本内容,递归进入其子元素
  2. // 该方法的效果类似于textContent 属性
  3. function textContent(e){
  4. var child, type, s = ""; // s 保存所有子节点的文本
  5. for(child = e.firstChild; child != null; child = child.nextSibling){
  6. type = child.nodeType;
  7. if(type === 3 || type === 4) // Text 和CDATASection 节点
  8. s += child.nodeValue;
  9. else if(type === 1) // 递归Element 节点
  10. s += textContent(child);
  11. }
  12. return s;
  13. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement