我想在单击(onfocus)时更改select2
的边框颜色。
我尝试这样做,但是它会更改选择内容的边框颜色,如下所示。如何指定边框颜色?
$('.sf-multi-select').select2({
placeholder: 'Select or type to search',
closeOnSelect: false,
});
.select2-search__field:focus {
border: 1px solid #43AEA8 !important;
}
.sf-multi-select:focus {
border: 1px solid #43AEA8 !important;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.js"></script>
<link href="https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.6-rc.0/css/select2.min.css" rel="stylesheet" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.6-rc.0/js/select2.min.js"></script>
<select class="sf-multi-select" placeholder="Type to search" multiple="multiple">
<option value="17">Choce 1</option>
<option value="16">Choice 2</option>
</select>
最佳答案
你可以这样:
$('.sf-multi-select').select2({
placeholder: 'Select or type to search',
closeOnSelect: false,
});
.select2-container--default.select2-container--focus .select2-selection--multiple {
border: 1px solid red!important;
}
select {
width: 100%;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.js"></script>
<link href="https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.6-rc.0/css/select2.min.css" rel="stylesheet" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.6-rc.0/js/select2.min.js"></script>
<select class="sf-multi-select" placeholder="Type to search" multiple="multiple">
<option value="17">Choce 1</option>
<option value="16">Choice 2</option>
</select>
因此,您应该修改自己的焦点类
:focus
,而不是使用.select2-container--default.select2-container--focus