开发者

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

$(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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜