javascript - JS: How to print elements in a for loop with distinct #ids? -
i want print out jquery, several html elements, , each element should have distinct #id.
my code output elements, don´t know how make them different.
<input type='button' onclick="generartabla(5)" name='submit' value='how many?'> <div id="output"></div> function generartabla(cant) { var numero = 1; var celda = "mes <input type='text' name='nro"+numero+"'><br>"; ($i=0; $i<cant; $i++) { $('#output').append(celda); } }
each line should this:
mes <input type='text' name='nro1'><br> mes <input type='text' name='nro2'><br> mes <input type='text' name='nro3'><br>
etc.
and right outputs this:
mes <input type='text' name='nro1'><br> mes <input type='text' name='nro1'><br> mes <input type='text' name='nro1'><br>
put constructor inside loop , use loop variable
function generartabla(cant) { ($i=0; $i<cant; $i++) { var celda = "mes <input type='text' name='nro"+($i+1)+"'><br>"; $('#output').append(celda); } }
Comments
Post a Comment