在JQuery中是否有firstChild.data的等价物?
给定以下HTML:
<p id='test'>Hello<span>world</span>/<p>下面的javascipt将返回:"Hello“
document.getElementById('test').firstChild.data给定的JQuery将返回:Hello< span>world</span>
$('#test').text()我如何才能做到这一点?
发布于 2012-06-06 23:45:54
您需要一个文本节点,这样就可以使用.contents
$("#test").contents().first().text();发布于 2012-06-06 23:44:00
试试这个:
$('#test').contents()[0].nodeValue;contents()帮助你获取文本节点。
https://stackoverflow.com/questions/10917575
复制相似问题