开发者

problem with cloned field

开发者 https://www.devze.com 2023-03-05 04:26 出处:网络
i have this code that wotks well now i am trying to开发者_StackOverflow change <input id=\"input1\" /> to <div id=\"input1\"> </div> Here.

i have this code that wotks well

now i am trying to开发者_StackOverflow change <input id="input1" /> to <div id="input1"> </div> Here.

The problem is the id, it is supposed change, like input1, input2, but in the second example the new divs always have the same id.

In the first example the name of the id's are input1, input2, input3,...


Solved

 $('#btnAdd').click(function() {
        $('.btnDel:disabled').removeAttr('disabled');
        var c = $('.clonedInput:first').clone(true);
            c.children('div').attr('id','input'+ (++inputs) ).val('');
            c.children(':button').attr('name','btnDelete'+ (inputs) );
        $('.clonedInput:last').after(c);
    });


You are setting the attribute "name" not "id", so your code should read:

$('#btnAdd').click(function() {
    $('.btnDel:disabled').removeAttr('disabled');
    var c = $('.clonedInput:first').clone(true);
        c.children(':text').attr('id','input'+ (++inputs) ).val('');
        c.children(':button').attr('id','btnDelete'+ (inputs) );
    $('.clonedInput:last').after(c);
});
0

精彩评论

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