Javascript 使用JS添加更多输入
我试图使用JS的按钮添加更多的输入,但我想不通 因此,我的HTML中有以下代码:Javascript 使用JS添加更多输入,javascript,html,input,Javascript,Html,Input,我试图使用JS的按钮添加更多的输入,但我想不通 因此,我的HTML中有以下代码: <div id="ingredients" class="ingredients"> <h2 class="tk-freight-sans-pro">Ingredients</h2> <input type="text" placeholder="Ingredient"> <input type="text" placeho
<div id="ingredients" class="ingredients">
<h2 class="tk-freight-sans-pro">Ingredients</h2>
<input type="text" placeholder="Ingredient">
<input type="text" placeholder="Ingredient">
<input type="text" placeholder="Ingredient">
<br>
<button class="button" onclick="addIngredient();">Add Ingredient</button>
</div>
成分
添加成分
我的JS在这里:
function addIngredient() {
var list = document.getElementById("ingredients")
list.innerHTML += "<input type="text" placeholder="Ingredient">"
}
函数添加元素(){
var list=document.getElementById(“成分”)
list.innerHTML+=“”
}
有人知道发生了什么或我需要做什么吗?
谢谢 这是:
list.innerHTML+=“”
应该是这样的:
list.innerHTML+=“”
或者像这样:
list.innerHTML+=''
不能在由双引号包装的字符串中使用双引号。您必须对字符串中的引号进行转义,或者使用简单的引号来包装它
此外,您还应该放置一个
代码>在每个指令之后。@tns12-您应该接受正确的答案:)(假设它解决了您所问的问题,它应该)