且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在 Javascript 中动态添加文本框?

更新时间:2022-06-20 08:08:26

如果替换innerHTML,之前输入的值将被清除,为避免这种情况,您可以通过编程方式附加输入元素:

If you replace the innerHTML, the previously entered values will be cleared, to avoid that, you can append the input elements programmatically:

var input = document.createElement('input'); 
input.type = "text"; 
//...    
container.appendChild(input); 

检查 this 示例.