更改select2.js的背景颜色

时间:2017-06-16 06:41:55

标签: javascript jquery css jquery-select2

我在之前的项目中使用了select2.js(3.4.5),现在我需要对其进行一些更改。现在无法升级select2版本。

我需要更改background color搜索框的select2,我尝试了但我无法查看我的fiddle或代码段。用户从background-color:red选择选项后,我想要select box

我尝试使用jquery

将所有元素应用于CSS

$('.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;
&#13;
&#13;

0 个答案:

没有答案