这将克隆下拉选项:var Task_Resource = $('#Resources')。clone();然后我将它附加到#Task_table,如下所示。
但是如何克隆下拉列表并保留当前选择的选项?
$('#add_button').button({
text: false,
icons: {
primary: 'ui-icon-plusthick'
}
}).click(function( event ) {
event.preventDefault();
$( "#dialog" ).dialog({
autoOpen: true,
show: {
effect: "drop",
duration: 500
},
hide: {
effect: "drop",
duration: 500
},
width: 350,
modal: true,
buttons: {
"Add": function() {
var Task_name = $('#name').val();
var Task_pre = $('#Predecessor').val();
var Task_Start = $('#Start').val();
var Task_Duration = $('#Duration').val();
var Task_Duration_unit = $('#Duration_unit').val();
var Task_Resource = $('#Resources').clone();
var Task_Percent = $('#Complete').val();
var Task_Notes = $('#Notes').val();
var rowCount = $('#Task_table tr').length -1;
var dateStart = "Start_date_"+rowCount ;
$('#Task_table tbody').append('<tr class="row_sortable">' +
'<td class="project_table_cells">1</td>' +
'<td class="project_table_cells">'+Task_name+'</td>' +
'<td class="project_table_cells"><input title="" id="predecessor_" name="predecessor[]" class="predecessor" value="'+Task_pre+'" /></td>' +
'<td class="project_table_cells"><input title="" id="'+dateStart+'" name="Start_date[]" class="Start_date" value="'+Task_Start+'" /><td class="project_table_cells"></td>' +
'<td class="project_table_cells"><input title="" id="duration_" name="duration[]" class="duration" value="'+Task_Duration+'" /></td>' +
'<td class="project_table_cells"><select id="duration_unit_" onchange="" name="duration_unit[]" class="duration_unit"><option value="Days">Days</option><option value="Hours">Hours</option></select></td>' +
'<td class="project_table_cells"><select id="resources_" name="resources[]" class="resources">'+Task_Resource.html()+'</select></td>' +
'<td class="project_table_cells"><input title="" id="percent_complete_" class="percent_comp" name="percent_complete[]" value="'+Task_Percent+'"/></td>' +
'<td class="project_table_cells"></td></tr>');
$( this ).dialog( "close" );
},
Cancel: function() {
$( this ).dialog( "close" );
}
}
});
});