更新时间:2023-12-05 07:51:16
Use a common parameter like class
or data-attrbiutes
wherever possible. Common Ids are invalid.
Check this code,
$('#add').click(function () {
var n = $('.row').length + 1;
var temp = $('.row:first').clone();
temp.attr('id', temp.attr('id') + n); //avoiding duplicate ID
$('input:first', temp).attr('placeholder', 'Item #' + n)
$('.row:last').after(temp);
});
$(document).ready(function () {
$("#remove").click(function () {
$(".row:last").remove(); //Remove section.
});
});