我正在尝试检查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');
}
最佳答案
将您的字符串传递给$.trim
:
if(! $.trim($('p').clone().children().remove().end().text())) {
alert('WRONG! Paragraph does not have any text');
}
JSFiddle Demo
关于jquery - 如何在if语句内的克隆元素上使用`$ .trim()`?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/26439993/