コードを実行しようとしていますが、insertAfter は、最後ではなく最初の div タグの後に div を挿入します。
最後のものの後に動的に追加したい。
また、ユーザーが削除ボタンをクリックした場合、削除ボタンがクリックされた div を削除する必要があります。
私のキャプションもうまく機能していません。若干の微調整が必要です。
<script type="text/javascript" src="jquery.js"></script>
$(document).ready(function() {
var uniqueId = 1;
$("#addRequest").click(function() {
var RequestDiv = "#div_" + $('#combo_3 option:selected').val() + "_1";
var RequestTableCap = "tbl_" + $('#combo_3 option:selected').val();
if ($(RequestDiv).is(":visible")) {
var template = $(RequestDiv).clone();
uniqueId++;
template.find('input,select,textarea,table').each(function() {
var newId = this.id.substring(0, this.id.length - 1) + uniqueId;
$(this).prev().attr('for', newId); // update label for
this.name = this.id = newId; // update id and name (assume the same)
})
.end()
.attr('id', 'div_data_1_1_1_1_' + uniqueId)
.appendTo('#idRequestDetails');
var TableCaption = 'Request #: ' + uniqueId + ' ' + $('#combo_2 option:selected').text() + ' ' + $('#combo_1 option:selected').text() + ' (' + $('#combo_3 option:selected').text() + ')';
var tbcaption = document.getElementById('RequestTableCap').createCaption()
tbcaption.innerHTML = TableCaption
}
if ($(this).attr("enabled", true)) {
if ($("#div_data_1_1_1_1_1").is(":hidden")) {
$(RequestDiv).slideDown("fast"); //Slide Down Effect
var RequestTableCap = "tbl_" + $('#combo_3 option:selected').val();
var TableCaption = 'Request #: ' + uniqueId + ' ' + $('#combo_2 option:selected').text() + ' ' + $('#combo_1 option:selected').text() + ' (' + $('#combo_3 option:selected').text() + ')';
var tbcaption = document.getElementById(RequestTableCap).createCaption()
tbcaption.innerHTML = TableCaption;
}
}
else {
$(RequestDiv).slideUp("fast"); //Slide Up Effect
}
});
$('.removeReq').click(function() {
$(this).closest.attr('div').remove();
});
});