arm*_*dfp 1 javascript regex each jquery
我有:
// $(this): <span class="class1"><span class="class2"></span> Some text</span>
$(this).children().each(function () {
console.log(this);
});
Run Code Online (Sandbox Code Playgroud)
从控制台我只得到了class2的范围,我怎么能得到文本?就像是:
['<span class="class2"></span>', 'Some text']
Run Code Online (Sandbox Code Playgroud)
$(this).children() 只返回作为元素的子节点.
您将需要用于$(this).contents()获取所有节点,包括文本节点.:)
然后,您可以过滤这些节点以获取元素和文本(请参阅节点类型):
$(this).contents().filter(function() {
return (this.nodeType === 1) || (this.nodeType === 3);
})
Run Code Online (Sandbox Code Playgroud)