如何使用javascript删除html文本属性标记

时间:2018-02-07 10:16:47

标签: javascript html regex

我有一段:

<p id="demo">Hi <b>R</b><u>o</u><i>h</i>it! It's soo good to see you</p>

如何以相同的格式替换Rohit一词和Akshat,以便我得到: 嗨 A k s 帽子!很高兴见到你

2 个答案:

答案 0 :(得分:1)

您可以执行以下操作:

&#13;
&#13;
var content = document.getElementById('demo').textContent;
document.getElementById('demo').textContent = content;
&#13;
<p id="demo">Hi <b>R</b><u>o</u><i>h</i>it! It's soo good to see you</p> 
&#13;
&#13;
&#13;

答案 1 :(得分:0)

请看一下
var text = $(&#39; #demo&#39;)。text();
的console.log(文本); //返回&#34;嗨罗希特!很高兴见到你&#34;