首页 > 语言 > JavaScript > 正文

jquery提取元素里的纯文本不包含span等里的内容

2024-05-06 14:35:23
字体:
来源:转载
供稿:网友
代码如下:
var text = '';
$('div').contents().each(function(){
if(this.nodeType === 3){
text += this.wholeText;
}
});

nodeType
元素element 1
属性attr 2
文本text 3
注释comments 8
文档document 9
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表

图片精选