<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>
转载于:https://www.cnblogs.com/fancyLee/p/8177290.html