how to use select2 bootstrap

▼魔方 西西 提交于 2019-12-13 06:49:16

问题


im new at select2 im using bootsrap v3.3.6

how to plugin the select2 bootstrap? i already input

<link href="css/select2.css" rel="stylesheet">
<link href="css/select2-bootstrap.css" rel="stylesheet">
<select id="position" style="width: 15%">
                <option value=""></option>
                <option>One</option>
                <option>Two</option>
<script src="js/select2.js"></script>
 $("#position").select2({
        allowClear:true,
        placeholder: 'Position'
      });

but the output still like the default select2. not like bootstrap, please help


回答1:


The $("#position").select2(..) instance should be inside script tags. Make sure you close the select tag. Make sure you're properly referencing the select2.css and select2.js and that there are no errors in the browser console.

http://codeply.com/go/YNg1JSaysI




回答2:


Please update your code as follows:-

 <link href="css/select2.css" rel="stylesheet">
 <link href="css/select2-bootstrap.css" rel="stylesheet">
 <select id="position" style="width: 15%">
 <option value=""></option>
 <option>One</option>
 <option>Two</option>
 <script src="js/select2.js"></script>
 <script>
 $("#position").select2({
 allowClear:true,
 placeholder: 'Position'
 });
 </script>

Links are as follows:

https://cdnjs.com/libraries/select2
https://cdnjs.com/libraries/select2-bootstrap-css
https://cdnjs.com/libraries/select2?ref=driverlayer.com/web

Hope that helps!



来源:https://stackoverflow.com/questions/36132875/how-to-use-select2-bootstrap

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!