Twitter bootstrap 3 对select2元素应用引导设置样式时出错

Twitter bootstrap 3 对select2元素应用引导设置样式时出错,twitter-bootstrap-3,jquery-select2,styling,Twitter Bootstrap 3,Jquery Select2,Styling,我有一份精选菜单 剥离版本,例如: 将has error应用于文本输入将在输入周围显示红色边框。这不适用于选择2菜单。我错过了什么 我正在使用bootstrap3和最新的select2 我已经尝试过该解决方案,但它不起作用。您发布的页面上的解决方案适用于较旧版本的select2。对于最新版本,请在此处使用此CSS代码: .has-error .select2-selection { border-color: rgb(185, 74, 72) !important; } 现在使用此

我有一份精选菜单

剥离版本,例如:


has error
应用于文本输入将在输入周围显示红色边框。这不适用于
选择2
菜单。我错过了什么

我正在使用
bootstrap3
和最新的
select2


我已经尝试过该解决方案,但它不起作用。

您发布的页面上的解决方案适用于较旧版本的
select2
。对于最新版本,请在此处使用此CSS代码:

.has-error .select2-selection {
    border-color: rgb(185, 74, 72) !important;
}
现在使用此代码并使用
has error
类,您可以获得适当的红色错误颜色:

<div class="form-group has-error">
 <select name="description_id" class="select2">
  <option>One</option>
  <option>Two</option>
  <option>Three</option>
  <option>Four</option>
 </select>
</div>

一个
两个
三
四


jsIDLE示例:

使用Bootstrap 3.3并选择2 4.0.6,错误样式可应用如下:

css:

jquery/javascript:

$('#YourSelect2ControlID').next().find('.select2-selection').addClass('has-error');

对于Select2控件,包含边框样式的对象不是
元素,而是
元素后面的嵌套
元素之一。该特定的span包含
。select2 selection
类。

就是这样,非常感谢,可以在12小时内奖励赏金:-)
$('#YourSelect2ControlID').next().find('.select2-selection').addClass('has-error');