【发布时间】:2018-12-11 05:00:16
【问题描述】:
所以我有这个代码,
spellNumber = 0
function createSpell() {
document.getElementById("spells").innerHTML +=
'<p><input type="text"></p><br />'
spellNumber += 1;
spellsActive = true
}
<a onClick="createSpell()" class="spellButton" style="background-color:#717171">Add a Spell</a>
<div id="spells"></div>
但是每当我尝试通过单击按钮添加另一个输入时,它都会擦除之前的所有输入。我怎样才能阻止这种情况发生?
【问题讨论】:
-
innerHTML 是添加更多 HTML 内容的坏方法。
标签: javascript html html-input