开发者

How to add new Element with unique name and delete specific element

开发者 https://www.devze.com 2023-01-26 11:45 出处:网络
$(function(){ $(开发者_开发百科\"#getitem\").click(function(){ var txtval = $(\"#txt\").val(); var number = ?????
$(function(){
   $(开发者_开发百科"#getitem").click(function(){
    var txtval = $("#txt").val();
    var number = ?????
    $('<input type="text" name=txt"'+number+'" value="'+txtval+'" />').appendTo('#form');
   });
});

Good Day,

Im having trouble solving this one, Basically I'm stuck. All I just need is create a new input type with a unique name preferably incremented numbers. then I have a function that can delete specific new element.. Hope you guys can help me.. Thanks in Advance..


$(function(){
    var namecounter = 0;
    $("#getitem").click(function() {
        namecounter++;
        var txtval = $("#txt").val();
        $('<input type="text" name="txt' + namecounter + '" value="' + txtval + '" />').appendTo('#form');
    });
})

Now the inputs get generated with name as txt1, txt2, ...

0

精彩评论

暂无评论...
验证码 换一张
取 消