引导程序选择显示的事件未触发

时间:2019-01-24 13:21:24

标签: javascript jquery html bootstrap-selectpicker

我正在为我的选择框使用引导选择。下拉列表打开后,我想执行一些操作。我使用以下代码,但显示的事件未触发。我也尝试过更改事件。什么都没有为我工作。有人建议这样做。

JS

$(function(){
   $('#c_select #hc_id').selectpicker();

   $('#c_select .selectpicker').on('shown.bs.select', function (e) {
    alert('dd');
   });

   $('.selectpicker').on('changed.bs.select', function (e) {
    console.log('ddddddddddd');
   });

})

<div id="c_select">
  <select id="hc_id" name="hc_id" data-focus-off="true" class="selectpicker change-cc" data-container="body" data-live-search="true">
    <option value="0" data-content="<span class='select-label first'>Select </span>"></option>
    <option value="1" data-content="<span class='select-label first'>AAAAAAAAAAA</span>"></option>
    <option value="2" data-content="<span class='select-label first'>BBBBB</span>"></option>
  </select>
</div>

2 个答案:

答案 0 :(得分:0)

尝试一下。

$(function(){
   var select = $('#c_select #hc_id').selectpicker();

   select.on('shown.bs.select', function (e) {
    alert('shown');
   });

   select.on('changed.bs.select', function (e) {
    alert('changed');
   });
})
<div id="c_select">
 <select id="hc_id" name="hc_id" data-focus-off="true" class="selectpicker change-cc" data-container="body" data-live-search="true">
   <option value="0" data-content="<span class='select-label first'>Select </span>"></option>
   <option value="1" data-content="<span class='select-label first'>AAAAAAAAAAA</span>"></option>
   <option value="3" data-content="<span class='select-label first'>BBBBB</span>"></option>
  </select>
</div>

下面是一个示例https://jsfiddle.net/caliberdev/8pc374xf/

答案 1 :(得分:-1)

尝试集中精力进行操作

 $('#c_select .selectpicker').on('focus', function (e) {
    alert('dd');
   });