<分区>
我正在尝试使用 javascript 将时间符号 ×
添加到 HTML 模板。不幸的是,HTML 将 & 字符代码作为字符串读取。我该如何解决这个问题?
HTML:
<button id='b'>Add Symbol</button>
<div>×</div>
<div id='container'></div>
JS:
document.getElementById('b').onclick = addSymbol;
function addSymbol() {
var pTag = document.createElement('p');
var pTagContent = document.createTextNode('×');
pTag.appendChild(pTagContent);
var container = document.getElementById('container');
container.appendChild(pTag);
}