0
3 개의 필드를 복제하는 코드 조각이 있지만, 3 개의 필드를 복제하면 내부에 입력 된 텍스트도 복제됩니다. 내부의 내용을 지우는 방법이 있습니다. 필드가 복제 될 때?텍스트를 복제하지 않고 필드 복제하기
$(document).ready(function() {
$('#btnAdd').click(function() {
var num = $('.clonedSection').length;
var newNum = new Number(num + 1);
var newSection = $('#clonedSection' + num).clone().attr('id', 'clonedSection' + newNum);
newSection.children(':first').children(':first').attr('id', 'name' + newNum).attr('name', 'name' + newNum);
newSection.children(':nth-child(2)').children(':first').attr('id', 'age' + newNum).attr('name', 'age' + newNum);
newSection.children(':nth-child(3)').children(':first').attr('id', 'school' + newNum).attr('name', 'school' + newNum);
$('.clonedSection').last().append(newSection);
$('.clonedSection').last().val(ping);
$('#btnDel').attr('disabled','');
if (newNum == 2)
$('#btnAdd').attr('disabled','disabled');
});
$('#btnDel').click(function() {
var num = $('.clonedSection').length; // how many "duplicatable" input fields we currently have
$('#clonedSection' + num).remove(); // remove the last element
// enable the "add" button
$('#btnAdd').attr('disabled','');
// if only one element remains, disable the "remove" button
if (num-1 == 1)
$('#btnDel').attr('disabled','disabled');
});
$('#btnDel').attr('disabled','disabled');
});
미리보기!
는 왜 두 번 똑같은 질문을 물어? http://stackoverflow.com/questions/3467457/cloning-a-field-with-text-in-it-clones-text-as-well –
이유가 없습니다. 사고였습니다! : / – Odyss3us