是否有可能获得createTextNode方法来呈现html标签? [英] Is it possible to get the createTextNode method to render html tags?
本文介绍了是否有可能获得createTextNode方法来呈现html标签?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
以下代码打印
应打印(b)应打印(/b)应打印
This should print(b)This should print(/b)This should print
<script>
function produceMessage(){
var msg= '<b>This should print</b>';
return msg;
}
</script>
<span id="mySpan"></span>
<script>
document.body.appendChild(document.createTextNode(produceMessage()));
document.write(produceMessage());
document.getElementById('mySpan').innerHTML=produceMessage();
</script>
推荐答案
否,文本节点不会打印任何HTML.而是创建一个元素,或使用文档片段以这种方式插入HTML.
No, a text node will not print any HTML. Instead, create an element, or use a document fragment to insert HTML in that way.
function boldHTML() {
var element = document.createElement("b");
element.innerHTML = "Bold text";
return element;
}
document.body.appendChild(boldHTML());
将打印粗体.
这篇关于是否有可能获得createTextNode方法来呈现html标签?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文