javascript - How to generate dynamic name and id for a textfield -
i have javascript function used generate textfield dynamically, when clicking previous textfield.
html
<input class="incfield" type="text" name="textfield" />
javascript
$(function () { var createnewfield = function () { var $node = $('<input class="incfield" type="text" name="textfield"); $node.one('click', createnewfield); $(this).after($node); } }; $('input.incfield').one('click', createnewfield);
});
the function working want textfield should have id
, name
tag, dynamically generated.
for example: first textfield id=t1 t2,...etc.
how can this?
$(function () { var cnt= 0; var createnewfield = function () { var $node = $('<input class="incfield'+cnt+'" type="text" name="textfield'+cnt+'"/>'); $node.one('click', createnewfield); $(this).after($node); cnt++; } };
this create dynamic name , id "incfield0" , "textfield0"
Comments
Post a Comment