我试图从jQuery中的动态下拉列表中选择多个值。我怎样才能实现任何值得赞赏的帮助。提前致谢。
// jQuery的
$.ajax({
type: 'GET',
url: url ,
dataType: 'json',
headers: {
accept: "application/json",
authorization:"key "+ bearer_token
}
}).done(function(data) {
var options = '<option value="" disabled="" selected="">Select Nearest Airport</option>';
data= data|| {};
$( "select option:selected" ).each( data, function( key, value ) {
options += '<option value="'+value.code+ ' - ' +value.name+'">'+value.code+ ' - ' +value.name+'</option>';
})
$('#AirportCode').html(options);
})
<div class="form-group col-md-6">
<label for="airport">Nearest Airport:</label>
<select id="AirportCode" name="AirportCode" multiple="multiple" class="form-control" placeholder="Select an Airport">
<option value="" disabled selected>Select Nearest Airport</option>
<option value="AirportCode" selected="selected"><div id="table"></div></option>
</select>
</div>
答案 0 :(得分:0)
尝试更改每个
$.each(data, function(key, value) {
options += '<option value="' + value.code + ' - ' + value.name + '">' + value.code + ' - ' + value.name + '</option>';
});