将一串HTML代码转换为实际的HTML

时间:2018-06-13 12:17:49

标签: javascript html

想象一下,我从服务器上收到了这个字符串:

'<h1>hello everyone</h1>'

如何将此字符串转换为可插入文档的实际HTML?

1 个答案:

答案 0 :(得分:0)

试一试:

var response = '<h1>hello everyone</h1>';
document.getElementById('localContainer').innerHTML = response;
// or
document.write(response);
<div id="localContainer"></div>

相关问题