gpt4 book ai didi

javascript - bootstrap-select 隐藏事件未触发

转载 作者:搜寻专家 更新时间:2023-11-01 05:00:16 24 4
gpt4 key购买 nike

我想弄清楚为什么在关闭 bootstrap-select 时无法触发关闭事件。

$(function() {

$('.selectpicker').on('hide.bs.dropdown', function () {
alert('hide.bs.dropdown');
})

});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<link href="//cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.2/css/bootstrap.css" rel="stylesheet"/>
<link href="//cdnjs.cloudflare.com/ajax/libs/bootstrap-select/1.7.2/css/bootstrap-select.css" rel="stylesheet"/>

<script src="//cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.2/js/bootstrap.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/bootstrap-select/1.7.2/js/bootstrap-select.js"></script>

<select class="selectpicker" multiple="true" data-done-button="true" data-live-search="true">
<option>Mustard</option>
<option>Ketchup</option>
<option>Relish</option>
</select>

最佳答案

hide.bs.dropdown事件绑定(bind)到选择器的父级,而不是选择器本身,因此您需要:

$(function() {

$('#selectpicker-container').on('hide.bs.dropdown', function () {
alert('hide.bs.dropdown');
})

});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<link href="//cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.2/css/bootstrap.css" rel="stylesheet"/>
<link href="//cdnjs.cloudflare.com/ajax/libs/bootstrap-select/1.7.2/css/bootstrap-select.css" rel="stylesheet"/>

<script src="//cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.2/js/bootstrap.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/bootstrap-select/1.7.2/js/bootstrap-select.js"></script>

<div id="selectpicker-container">
<select class="selectpicker" multiple="true" data-done-button="true" data-live-search="true">
<option>Mustard</option>
<option>Ketchup</option>
<option>Relish</option>
</select>
</div>

关于javascript - bootstrap-select 隐藏事件未触发,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33008805/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com