<div id="options-container"></div>
<script>
function createInputElements(num) {
const optionsContainer = document.getElementById("options-container");
for (let i = 0; i < num; i++) {
const input = document.createElement("input");
input.setAttribute("type", "text");
input.setAttribute("placeholder", `Input ${i + 1}`);
optionsContainer.appendChild(input);
}
}
const option = 3;
createInputElements(option);
</script>
这是基于选项编号动态创建多个输入字段的javascript代码,希望用react js编写
1条答案
按热度按时间s5a0g9ez1#
您可以使用useState来执行此操作: