我有一系列的引用如下:
<p>Being a graphic designer gets you used to rejection of your brilliance. So it’s good practice for dating. </p>
我希望他们看起来像这样:
Being a graphic designer gets you used to rejection of your brilliance. So it's good practice for dating.
我尝试使用innerHTML,但成效有限。
答案 0 :(得分:2)
使用document.createElement
方法创建一个临时span元素,其中html内容为字符串。稍后通过获取textContent
属性来获取文本内容。
var str = '<p>Being a graphic designer gets you used to rejection of your brilliance. So it’s good practice for dating. </p>';
// create a span element
var temp = document.createElement('span');
// set the html to the element
temp.innerHTML = str;
// get the text content
console.log(temp.textContent);
&#13;