gpt4 book ai didi

javascript - 如何从具有跨度的 Div 中获取内容也有一些内容?

转载 作者:行者123 更新时间:2023-11-30 09:04:18 25 4
gpt4 key购买 nike

如何从具有 span 且也有一些内容的 Div 中获取内容?

<div id="test">
this is a DIV
<span>
This is a span
</span>
</div>

alert(document.getElementById('test').innerText);

代码提醒我 This is a DIV This is a span.Im looking to get the content only from the DIV.

最佳答案

使用nodeValue :

document.getElementById('test').childNodes[0].nodeValue;

Demo on jsfiddle

关于javascript - 如何从具有跨度的 Div 中获取内容也有一些内容?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6441947/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com