如何使用JavaScript获得没有HTML元素的纯文本?
2022-08-30 02:42:18
我在HTML中有1个按钮和一些文本,如下所示:
function get_content(){
// I don't know how to do in here!!!
}
<input type="button" onclick="get_content()" value="Get Content"/>
<p id='txt'>
<span class="A">I am</span>
<span class="B">working in </span>
<span class="C">ABC company.</span>
</p>
当用户单击该按钮时,中的内容将成为以下预期结果:<p id='txt'>
<p id='txt'>
// All the HTML element within the <p> will be disappear
I am working in ABC company.
</p>
任何人都可以帮我如何编写JavaScript函数吗?
谢谢。