フォームを設定して機能させることに成功しました。ただし、2つの問題があります。
a)削除ボタンが機能しない(フォーム要素の最後の行が削除されます)
b)これはマイナーなマークアップの問題です。「追加」を押してフォーム要素の新しい行を追加すると、新しい行を作成する代わりに<ul></ul>
、既存の行に読み込まれます。<ul></ul>
これがデモリンクですhttp://jsfiddle.net/34rYv/1/
そして、以下の私のJSコード
$(document).ready(function() {
$('#btnAdd').click(function() {
var num = $('.clonedSection').length;
var newNum = new Number(num + 1);
var newSection = $('#pq_entry_' + num).clone().attr('id', 'pq_entry_' + newNum);
newSection.children(':first').children(':first').attr('id', 'year_' + newNum).attr('name', 'year_' + newNum);
newSection.children(':nth-child(2)').children(':first').attr('id', 'qualification_' + newNum).attr('name', 'qualification_' + newNum);
newSection.children(':nth-child(2)').children(':first').attr('id', 'university_' + newNum).attr('name', 'university_' + newNum);
$('.clonedSection').last().append(newSection)
$('#btnDel').attr('disabled', '');
if (newNum == 5) $('#btnAdd').attr('disabled', 'disabled');
});
$('#btnDel').click(function() {
var num = $('.clonedSection').length; // how many "duplicatable" input fields we currently have
$('#pq_entry_' + 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');
});