[英]Create number of inputs (with prefix) based on user input
I want to create a dynamic number of number inputs based on the number that I enter in a first input. 我想根据我在第一个输入中输入的数字来创建动态数字输入。 Per example, if I enter "3", it should create 3 rows: 例如,如果我输入“ 3”,它将创建3行:
row1------(input) row2------(input) row3------(input) row1 ------(输入)row2 ------(输入)row3 ------(输入)
The input is entered here: 在此处输入输入:
<tr>
<td align="center" bgcolor="#D4D4D4">Cantidad de arreglos:</td>
<td align="center" bgcolor="#D4D4D4"><input type="number" id="cantidadArreglos" onchange="espacioArreglos(this.value);" size="1"></td>
</tr>
On changing the number of this input, the function "espacioArreglos" should be called and generate a number input for each row. 更改此输入的编号时,应调用函数“ espacioArreglos”并为每一行生成一个数字输入。
How can I do this? 我怎样才能做到这一点? My function does nothing upon changing the value of the input "cantidadArreglos". 更改输入“ cantidadArreglos”的值时,我的函数不执行任何操作。
function espacioArreglos() {
for(var i = 0; i <= cantidadArreglos; i++)
{
var cantidadArreglos = document.getElementById('cantidadArreglos').value;
var tb = document.createElement('input');
}
}
I don't have enough rep to comment just yet but I believe oninput is what you are looking for. 我目前没有足够的代表发表评论,但我相信oninput是您想要的。 onchange only fires when you press enter for text fields. 仅当您按Enter键输入文本字段时, onchange才会触发。 Also I would get the value of your text field before your for
loop. 我也将在for
循环之前获取您的文本字段的值。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.