select2-demo

<div class="input-group col-md-6">
<span>城市</span>
<select name="input-city" id="input-city" class="input-city"></select>
</div>

<link rel="stylesheet" href="select2/select2.css">
<script src="jquery-2.2.3.min.js"></script>
<script src="select2/select2.full.js"></script>
<script>
$(function () {
var cities = [{id: 1, text: 'beijing'}, {id: 2, text: 'henan'}, {id: 3, city: 'guangxi'}];
$('#input-city').select2({//初始化select2
placeholder: "选择城市",
allowClear: true,
language: {
noResults: function () {
return '没找到记录';
}
},
data:cities
/*ajax: {
url: '',
dataType: 'json',
res: function (data) {//返回结果
return data;
}
}*/
})
})
//alert($("#input-city option:selected").val()) //1 2 3
//var text=$("#input-city option:selected").text(); //henan


</script>
posted @ 2018-01-02 15:09  一叶一菩提22  阅读(307)  评论(0编辑  收藏  举报