我可以在javascript中将字符串转换为HTML吗?
let description = "<a className="peoplelink" id="ether">Ether</a> // is render as 'the historian of the'";
let html= // I know that it is easy to do with jquery by using .html() method, but can we convert a string to HTML in javascript?
答案 0 :(得分:1)
无需转换,是一个简单的字符串到innerHtml:
即:
const markup = `
<div class="person">
<h2>
${person.name}
</h2>
<p class="location">${person.location}</p>
<p class="bio">${person.bio}</p>
</div>
`;
document.body.innerHTML = markup;