problem with cloned field
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);
});
精彩评论