0
我有ddl(下拉列表)從另一個ddl的更改事件後從數據庫填充,但我想從數據庫填充它後更改此ddl的值。jQuery等待選擇從數據庫中填充
例子:
// This work very well
$("#ddlGroups").on('change',function(){
// Load data from database and populate ddlUsers
// response is loaded from database with $.ajax
// Query Example: SELECT User_ID, Username FROM tblUsers WHERE Group_ID = [Group_ID] (Just for undrestanding the question)
var Records = response.d;
$("#ddlUsers").empty();
$.each(Records, function(){
var _Key = this.User_ID;
_Value = this.Username;
$("#ddlUsers").append($("<option />").val(_Key).text(_Value));
});
});
// When button clicked then trigger ddlGroups change event and assign select option from ddlUsers
var _UserID = User_ID_From_Database; // Loaded from Database when button clicked
$("#ddlGroups").trigger('change'); // Users are loaded from database based on group ID
$("#ddlUsers").val(_UserID); // But this dosn't change
如何或我是否ddlUsers加載不,我試圖在循環,但它永遠不會停止。
你能更清楚嗎?也許向我們展示更多代碼? – melancia
更改了所有問題。 –
我認爲你的意思是['trigger'](http://api.jquery.com/trigger)而不是['tigger'](http://en.wikipedia.org/wiki/Tigger)。 – lonesomeday