我在之前的项目中使用了select2.js(3.4.5)
,现在我需要对其进行一些更改。现在无法升级select2
版本。
我需要更改background color
搜索框的select2
,我尝试了但我无法查看我的fiddle或代码段。用户从background-color:red
选择选项后,我想要select box
。
我尝试使用jquery
$('.select2-choices').attr("style",'background-color:#EA4335 !important');
$('.select2-choices > *').attr("style",'background-color:#EA4335 !important');
你也可以在我的代码中看到。
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/normalize/5.0.0/normalize.min.css">
<link rel='stylesheet prefetch' href='https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.1.0/css/bootstrap.css'>
<link rel='stylesheet prefetch' href='https://cdnjs.cloudflare.com/ajax/libs/select2/3.4.5/select2.css'>
<div class="container-fluid">
<select id="e2_2" multiple="multiple" style="width:100%" class="select2-multi-col">
<optgroup label="Eastern Time Zone">
<option value="CT">Connecticut</option>
<option value="DE">Delaware</option>
<option value="FL">Florida</option>
<option value="GA">Georgia</option>
<option value="IN">Indiana</option>
<option value="ME">Maine</option>
<option value="MD">Maryland</option>
<option value="MA">Massachusetts</option>
<option value="MI">Michigan</option>
<option value="NH">New Hampshire</option>
<option value="NJ">New Jersey</option>
<option value="NY">New York</option>
<option value="NC">North Carolina</option>
<option value="OH">Ohio</option>
<option value="PA">Pennsylvania</option>
<option value="RI">Rhode Island</option>
<option value="SC">South Carolina</option>
<option value="VT">Vermont</option>
<option value="VA">Virginia</option>
<option value="WV">West Virginia</option>
</optgroup>
</select>
</div>
<script src='https://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js'></script>
<script src='https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.1.0/js/bootstrap.min.js'></script>
<script src='https://cdnjs.cloudflare.com/ajax/libs/select2/3.4.5/select2.min.js'></script>
<script>
$("#e2_2").select2({
placeholder: "Select a state or many…"
});
/* apply js to select box to change background color */
$('document').ready(function(){
$('.select2-choices').attr("style",'background-color:#EA4335 !important');
$('.select2-choices > *').attr("style",'background-color:#EA4335 !important');
});
</script>
</body>
</html>
&#13;