简体   繁体   中英

bootstrap-select shown event not firing

I am using bootstrap select for my select box. I want to do some action once the drop down opened. I used the following code but shown event not getting fired. I tried with changed event also. Nothing worked for me. Some one suggest a way to do this.

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>

Try this.

$(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>

Here is an example https://jsfiddle.net/caliberdev/8pc374xf/

Try Doing your action on focus

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM