假设我有这个:
<div class='myDiv'>
<p>hello</p>
hello
<p>Hello</p>
</div>
如何使用jQuery获取两个P标记之间的文本hello?
发布于 2011-06-18 00:10:59
$('.myDiv')
.contents()
.filter(function() {
return this.nodeType == Node.TEXT_NODE;
}).text();
How do I select text nodes with jQuery?
http://jsfiddle.net/6us8r/
发布于 2011-06-18 00:08:18
js1568有一个更好的方法
$('div.myDiv').filter('p').text()可能会起作用。
我收回它,过滤器就不能工作了。可能是这样的:
var jText = $('div.myDiv').clone();
jText.find('p').remove();
jText.text();
https://stackoverflow.com/questions/6388507
复制相似问题