我是jQuery和Javascript的新手。我有来自jquery ajax sucess回调的以下数据。
["Man","KFC","fsdfds","ETA","Star","SCity ","TESTGB"]
现在,我想在成功回调中填充这些数据。
success: function(data) {
// Call this function on success
alert(data);
var builder_arr=data.split(',');
for (var i=0;i<builder_arr.length;++i)
{
builder_arr[i]+':'+builder_arr[i];
}
}
我不知道如何在选择内填充它 我怎么能这样做?
答案 0 :(得分:0)
<强> HTML 强>
<select id="mydropdown">
</select>
<强> JS 强>
function onSuccess(data) {
$.each(data, function (index, value) {
$('#mydropdown').append($('<option/>', {
value: value,
text : value
}));
});
}
var data = ["Man","KFC","fsdfds","ETA","Star","SCity ","TESTGB"];
onSuccess(data);
注意: 鉴于上述情况,这只是一个最好的猜测。