我正在尝试检查一个段落(不包括任何嵌套的子标记)是否包含文本-但现在它的缩进会产生误报-那么如何使用它$.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');
}
将您的字符串传递给$.trim
:
if(! $.trim($('p').clone().children().remove().end().text())) {
alert('WRONG! Paragraph does not have any text');
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句