且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

将字符串转换为Javascript中的html标签

更新时间:2023-11-07 17:19:52

var string = "<strong>asdfadfsafsd</strong>",
    results = document.getElementById("results")
    results.innerHTML = string;
    results.innerHTML =    results.textContent;

<div id="results"></div>

首先将其加载为html。然后将其提取为文本,然后再次将其加载为HTML:)

At first load the it as html. Then fetch it as text and then again load it as HTML :)

引用HTML实体