JQuery 中是否有 firstChild.data 的等价物?
给定以下 HTML:
<p id='test'>Hello<span>world</span>/<p>
下面的 javascipt 将返回:“你好”
document.getElementById('test').firstChild.data
给定的 JQuery 将返回:Hello< span>world</span>
$('#test').text()
我怎样才能做到这一点?
最佳答案
你想要一个文本节点,所以你可以使用.contents
:
$("#test").contents().first().text();
关于javascript - jquery firstChild.data 等效,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10917575/