我试过使用document.createElement,它可以很好地添加文本框,但我不能递增ID名称。 我在地铁应用程序中使用它。我试图在有序列表中添加文本框onclick按钮使用JavaScript,也增加了ID名称,同时添加文本框
0
A
回答
0
<form>
No. of lines:
<input type="text" id="number" value="0"/>
<br/>
<input type="button" id="button" value="Add Line" />
</form>
<div>
<ol id="linedata">
</ol>
</div>
document.getElementById('button').addEventListener("click", incrementValue);
function incrementValue() {
var value = parseInt(document.getElementById('number').value, 10);
value = isNaN(value) ? 0 : value;
value++;
document.getElementById('number').value = value;
var list = document.createElement('li');
var box = document.createElement('input');
box.type = 'text';
box.id = 'line' + value;
box.placeholder='Line ' + value;
list.appendChild(box);
document.getElementById("linedata").appendChild(list);
}
0
function textBox(noOfInputTag){
noOfInputTag = noOfInputTag*1; // Convert to Number
//noOfInputTag is used to get total textbox you want to create
for(var i = 0; i <= noOfInputTag; i++){
var textbox = document.createElement('input');
textbox.type = 'text';`enter code here`
textbox.id = 'textBox_' + i; // As number of textbox increases id get incremented
document.body.appendChild(textbox);
}
}
textBox(2);
+0
请添加说明,说明您做了什么 –
+0
function addInput(){var i = 0; i <= 50; i ++)var input = document.createElement(“input”); input.type =“text”; input.id =“name”+ i; document.getElementById(“list”)。appendChild(input); } } –
+0
您的代码运行良好,那么问题是什么? –
相关问题
- 1. 添加按钮,动态也添加文本框,动态AngularJS
- 2. 在word文本框中添加按钮
- 3. 使用按钮在javascript中添加多个文本框
- 4. 文本框后cliked我如何使按钮添加到文本
- 5. 在按钮上添加文本框点击使用javascript
- 6. 将按钮添加到文本框
- 7. 从javascript中添加标签或添加文本框的文本
- 8. 添加文本框
- 9. 添加文本框
- 10. 添加文本框
- 11. 使用javascript添加新文本框
- 12. 添加文本框点击添加按钮
- 13. 如何在javascript中添加按钮到文本框的内容
- 14. 在文本框中添加叠加按钮
- 15. 不想清除文本框,同时点击添加按钮
- 16. 将文本从文本框添加到列表视图列
- 17. 这里我想在文本框中添加按钮值
- 18. 如何修改可排序的文本框,同时也能够添加文本?
- 19. 在地图中添加文本框
- 20. HTML列表添加文本框
- 21. 在点击sproutcore中的按钮时添加文本框
- 22. 添加到列表,javascript。使用按钮将文本框的值复制到另一个文本框
- 23. 单击按钮时如何将文本框添加到表格
- 24. 消失在动态添加文本框的文本使用JavaScript
- 25. 如何在BlogSpot文章中添加文本框和按钮?
- 26. asp.net文本框添加行为ID
- 27. 如何ID添加到autogenerafted文本框
- 28. 如何在使用javascript的表格中添加文本框?
- 29. QT创建按钮,将文本添加到文本编辑框
- 30. 当按下按钮时添加文本框
您是否尝试过使用For循环递增? https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for – Josh
你如何向createElement提供“ID名称”? – Nate
我正在使用createElement添加文本框 –