有问题。拿这个HTML:
<p><span>js fiddle is a playground for
web developers, a tool which may be
used in many ways. One can use it as
an online editor for snippets build
from HTML, CSS and JavaScript. The
code can then be shared with others,
embedded on a blog, etc. Using this
approach, JavaScript developers can
very easily isolate bugs. We aim to
support all actively developed
frameworks - it helps with testing
compatibility.</span></p>
我运行此代码:
var textNodes = $('p').contents().filter(function() {
return this.nodeType == 3 && this.nodeValue.length > 150;
}).parent().parent();
$(textNodes).css('border', '2px solid black');
我遇到的问题是contents()
只降低了一级...我想要的是测试p
元素是否包含超过150个nodeType == 3
个字符。如果我这样做contents().contents()....