jquery select2不显示向下箭头图标

zyfwsgd6  于 2023-05-17  发布在  jQuery
关注(0)|答案(7)|浏览(314)

我的select2是完美的工作,我只是有一个小错误,从选择框的箭头向下的图标是不显示,你知道的家伙为什么?

这让用户有点困惑我试图找到错误,但我不能修复错误,你们能帮我吗?代码在这里不工作,但在jsfiddle链接中工作。
jsfiddle:http://jsfiddle.net/yszv1ob2/

$("#e1").select2();
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<script src="http://cdnjs.cloudflare.com/ajax/libs/select2/3.2/select2.min.js"></script>
<link rel="stylesheet" href="http://cdnjs.cloudflare.com/ajax/libs/select2/3.2/select2.css">

<select multiple id="e1" style="width:300px">
  <option value="AL">Alabama</option>
  <option value="Am">Amalapuram</option>
  <option value="An">Anakapalli</option>
  <option value="Ak">Akkayapalem</option>
  <option value="WY">Wyoming</option>
</select>
h43kikqp

h43kikqp1#

对于Select2版本4.0.5+,此代码完全复制了单选箭头。

.select2-selection--multiple:before {
    content: "";
    position: absolute;
    right: 7px;
    top: 42%;
    border-top: 5px solid #888;
    border-left: 4px solid transparent;
    border-right: 4px solid transparent;
}
5fjcxozz

5fjcxozz2#

您已经使用了多选下拉菜单和使用插件(Select2)不添加下拉箭头在多选下拉。因此,如果你想添加下拉箭头,你必须添加一些自定义CSS如下。

ul.select2-choices {
    padding-right: 30px !important;
}

ul.select2-choices:after {
    content: "";
    position: absolute;
    right: 10px;
    top: 50%;
    transform: translateY(-50%);
    border-top: 5px solid #333;
    border-left: 5px solid transparent;
    border-right: 5px solid transparent;
}
nr7wwzry

nr7wwzry3#

$(function () {
  $("#select1").select2();
});
.select2-container--default .select2-selection--multiple:before {
    content: ' ';
    display: block;
    position: absolute;
    border-color: #888 transparent transparent transparent;
    border-style: solid;
    border-width: 5px 4px 0 4px;
    height: 0;
    right: 6px;
    margin-left: -4px;
    margin-top: -2px;top: 50%;
    width: 0;cursor: pointer
}

.select2-container--open .select2-selection--multiple:before {
    content: ' ';
    display: block;
    position: absolute;
    border-color: transparent transparent #888 transparent;
    border-width: 0 4px 5px 4px;
    height: 0;
    right: 6px;
    margin-left: -4px;
    margin-top: -2px;top: 50%;
    width: 0;cursor: pointer
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.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 multiple id="select1" style="width: 300px">
  <option value="AL">Alabama</option>
  <option value="Am">Amalapuram</option>
  <option value="An">Anakapalli</option>
  <option value="Ak">Akkayapalem</option>
  <option value="WY">Wyoming</option>
</select>

来源:https://github.com/select2/select2/issues/167#issuecomment-322461384

xfb7svmp

xfb7svmp4#

基于Adam Love's answer,这段代码使用FontAwesome chevron down图标(尽管你可以很容易地将它换成不同的图标):

.select2-container--default .select2-selection--multiple {
    padding-right: 20px;
}
.select2-container--default .select2-selection--multiple::after {
    position: absolute;
    right: 5px;
    top: 42%;
    font-family: 'Font Awesome 5 Free';
    font-weight: 900;
    -webkit-font-smoothing: antialiased;
    display: inline-block;
    font-style: normal;
    font-variant: normal;
    text-rendering: auto;
    line-height: 1;
    content: "\f078";
    font-size: 0.7rem;
}
8i9zcol2

8i9zcol25#

$("#e1").select2();
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<script src="http://cdnjs.cloudflare.com/ajax/libs/select2/3.2/select2.min.js"></script>
<link rel="stylesheet" href="http://cdnjs.cloudflare.com/ajax/libs/select2/3.2/select2.css">

<select multiple id="e1" style="width:300px">
  <option value="AL">Alabama</option>
  <option value="Am">Amalapuram</option>
  <option value="An">Anakapalli</option>
  <option value="Ak">Akkayapalem</option>
  <option value="WY">Wyoming</option>
</select>
liwlm1x9

liwlm1x96#

您可以添加此css代码,它将应用于selectspan

.select2-selection__arrow {
  height: 26px;
  position: absolute;
  top: 10px;
  right: 7px;
  width: 20px;
}
.select2-selection__arrow b{
    border-color: #009688 transparent transparent transparent;
    border-style: solid;
    border-width: 5px 4px 0 4px;
    height: 0;
    left: 50%;
    margin-left: -4px;
    margin-top: -2px;
    position: absolute;
    top: 50%;
    width: 0;
  }
x759pob2

x759pob27#

只需添加class ='form-select',它就可以工作了

相关问题