Home >Web Front-end >JS Tutorial >Experience using jquery select2 (recommended)
How to select the specified item after ajax loads the drop-down box data?
html:
<script src="/statics/matrix-admin/js/jquery.min.js"></script> <script src="/statics/matrix-admin/js/select2.min.js"></script> <select id='mySelect'></select>
js:
$(function(){ $('#mySelect').select2(); $.ajax({ success:function(data){ $('#mySelect').append(); $('#mySelect').select2('val','val1');//调用select2('val','指定项value')方法选中指定项,否则无任何项被选中。如果设置的值不存在,则默认选择第一项 } }) })
The above The usage experience of jquery select2 (recommended) is all the content shared by the editor. I hope it can give you a reference, and I also hope that everyone will support the PHP Chinese website.
For more jquery select2 usage experience (recommended) and related articles, please pay attention to the PHP Chinese website!