html
<div> <select id="mobile" class="form-control" multiple="multiple" name="mobile[]"> <option value="0">请选择</option> </select> <p>请输入手机号并回车。若存在会员信息,可在下拉框选中</p> </div>
js var $mobile = $("#mobile"); $mobile.select2({ ajax: { url: "", dataType: 'json', processResults: function (result) { var data = $.map(result, function (obj) { obj.id = obj.id || obj.pk; obj.text = obj.text || obj.name; return obj; }); return { results: data }; }, }, data:[ <?php if(ckFeiteiArr($mobiles)) { ?> <?php foreach($mobiles as $m) { ?> {id:"<?php echo $m?>", text:"<?php echo $m?>"}, <? } ?> <? } ?> ], }); <?php if(ckFeiteiArr($mobiles)) { ?> $mobile.val([<?php echo implode(',', $mobiles )?>]).trigger('change'); <? } ?>
end.