您可能希望將選定的選項保存在某處,並在對話框打開時將<select>
的值設置爲該保存的值。
像下面的東西應該讓你開始。
var orderData = {}; // -- An object to save the data into
var activeEl; // -- Keep track of which button we've clicked
$('#btnOrder1,#btnOrder2').click(function(){
// -- open the dialog
$('#dialog').dialog({
title:'Order Options',
modal: true
});
// -- set the last clicked button to the ID of the one we clicked...
activeEl = this.id;
// -- set the select's option to the value we've stored.
// -- Unless we don't have a value, in which case we'll use "empty".
$('#selOrderOption').val(orderData[activeEl] || '');
});
// -- set up the save click handler
$('#btnSave').click(function(){
// -- save the selected value, keyed by the active button's ID
orderData[activeEl] = $('#selOrderOption').val();
$('#dialog').dialog("close");
});
http://jsfiddle.net/daveSalomon/7Lds66td/
您可以張貼的jsfiddle什麼你目前有哪些? – 2014-11-06 21:52:52