在下面的代碼中,我有動態下拉列表,我想要一個值被選中。但是,當我傳遞一個值被選中。沒有值越來越binded.Ples幫我做到這一點。將選定的值設置爲動態下拉
if (type == "DropDownList") {
newdiv.innerHTML += "<select class=\"form-control\" data-error=\"Please Provide " + DisplayName + "\" name=\"" + Name + "\" id=\"" + Name + "\"/>";
$('#divComplete').append(newdiv);
Load(id, Name, FieldValue);
}
function Load(sFieldID, sControleID, FieldValue) {
alert(FieldValue); if (sFieldID == '')
return;
var dataString = JSON.stringify({
strProjectID: iProjectID
});
$.ajax({
type: "POST",
contentType: "application/json; charset=utf-8",
url: "Sample.aspx/test",
dataType: "json",
async: false,
data: dataString,
success: function (data) {
var locations = JSON.parse(data.d);
$('#' + sControleID).html("");
$.each(locations, function (i, item) {
alert(item);
$('#' + sControleID).append($('<option selected=\"true\" value=\"' + FieldValue + '\">', {
value: item.EnumText,
text: item.EnumText
}));
});
},
error: function (result) {
}
});
}
什麼是id'的'值(傳遞給'負荷()')?它是否設置?正如預期的那樣,您的'alerts()'是否有很多'item's? 'data.d'包含什麼? –
[Set selected selected option of select box]可能重複(http://stackoverflow.com/questions/4680075/set-selected-option-of-select-box) – IROEGBU