我有一段克隆三个字段的代码,但是当它克隆了三个字段时,它还克隆了在其中输入的文本,有没有办法在克隆时清除字段内的内容?< / p>
$(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');
});
提前Thanx!
答案 0 :(得分:1)
您可以清除输入元素:
newSection.find(':input').val('');