首页 > 编程技术 > js

jquery提取元素里的纯文本

发布时间:2013-10-3 13:47

代码如下:

var text = ''; 
$('div').contents().each(function(){ 
if(this.nodeType === 3){ 
text += this.wholeText; 
} 
});

 只提取文本,其他html代码忽略


nodeType

元素element1
属性attr2
文本text3
注释comments8
文档document9
标签:[!--infotagslink--]

您可能感兴趣的文章: