我正在为我的选择框使用引导选择。下拉列表打开后,我想执行一些操作。我使用以下代码,但显示的事件未触发。我也尝试过更改事件。什么都没有为我工作。有人建议这样做。
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>
答案 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>
答案 1 :(得分:-1)
尝试集中精力进行操作
$('#c_select .selectpicker').on('focus', function (e) {
alert('dd');
});