gpt4 book ai didi

javascript - 单击时在 Select2 多选上指定边框颜色

转载 作者:太空宇宙 更新时间:2023-11-04 00:56:13 24 4
gpt4 key购买 nike

我想在单击 (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

关于javascript - 单击时在 Select2 多选上指定边框颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54686233/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com