将字符串转换为Javascript中的html标签 [英] Convert string to html tags in Javascript
本文介绍了将字符串转换为Javascript中的html标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想将以下字符串转换为HTML标记,并将其放在div中。
I want to convert the following string to HTML tags and place it inside my div.
<strong>asdfadfsafsd</strong>
我正在使用以下代码将其放在div中:
I am using the following code to place it inside my div:
var message = "<strong>testmessage</strong>";
document.getElementById('message').innerHTML = bericht;
问题是我现在在div中看到以下内容:
The problem is that I see the following in my div now:
<strong>testmessage</strong>
但我想查看:
testmessage
出了什么问题?
推荐答案
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 :)
这篇关于将字符串转换为Javascript中的html标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文