我正在使用一个 jQuery 模态对话框来显示一个下拉列表供用户选择。我通过将它们附加到空的下拉列表来动态填充下拉列表。这第一次有效,然后第二次通过它只显示默认选项,而不是动态选项?
function showExportDialog() {
//create html string for drop down list
var selectString = "<div><select id=\"selectExport\" style=\"width: 100%\"><option>-- Select Export --</option></select></div>";
//initialize the dialog - register click handler
var $dialog = $(selectString).dialog({
autoOpen: false,
title: 'Export Dialog',
modal: true,
//dims screen to bring dialog to the front
width: 500,
buttons: {
"export": function() {
exportAs($('#selectExport').val());
$(this).dialog('close');
}
}
});
//dynamically generate drop down list based on model type
switch (modelType) {
case "SPATIAL_STATISTICAL":
$('#selectExport').html(''); //clear the drop down list
$("<option value='csv'>CSV (comma separated value)</option>").appendTo("#selectExport");
$("<option value='tab'>TSV (tab separated value)</option>").appendTo("#selectExport");
$("<option value='heat'>Heatmap (google heatmap layer format)</option>").appendTo("#selectExport");
break;
case "STATISTICAL":
break;
case "GRAPH":
break;
case "PATTERN":
break;
default:
throw "Invalid ModelType '" + modelType + "'";
}
//open the dialog
$dialog.dialog('open');
}
这是一个显示我的问题的小提琴:http: //jsfiddle.net/b3v3R/21/
要重现问题:
- 单击“显示导出下拉菜单”
- 从下拉列表中选择一个选项
- 点击“导出”
- 再次单击“显示导出下拉菜单”
有什么想法吗?