2
我试图检查if a paragraph (excluding any nested child tags) contain text - 但现在它的缩进发出误报 - 那么如何使用$.trim()
来摆脱它们?
http://jsfiddle.net/frank_o/td8t4gpv/2/
HTML:
<div>
<p>
<a>Should not react to this</a>
</p>
</div>
JS:
if($('p').clone().children().remove().end().text()) {
console.log('WRONG! Paragraph does not have any text');
}
你想修剪一个tage tex里面的所有东西吗? – 2014-10-18 13:04:28
本质上'.text()'应该被应用到'$('p')'的修剪版本,即。 '
...
'。 – 2014-10-18 13:05:35