我的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>
答案 0 :(得分:15)
您使用了多选下拉菜单并使用了插件(Select2),请勿在多选下拉列表中添加下拉箭头。因此,如果您想添加下拉箭头,则必须添加一些自定义CSS,如下所示。
@Component
答案 1 :(得分:9)
对于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;
}
答案 2 :(得分:1)
$("#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>
答案 3 :(得分:1)
未显示,因为您在select标记中包含multiple
属性,只需删除它:
<select 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>
答案 4 :(得分:1)
基于Adam Love's answer,此代码使用了FontAwesome人字形向下图标(尽管您可以轻松地将其换成其他图标):
.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;
}
答案 5 :(得分:0)
$(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