bootstrap-select select/deselect所有选项点击都不能触发事件?

bootstrap-select select/deselect all option click can't firing event?

这可能是一个简单的问题,但我无法在任何地方找到答案或让它起作用。

我正在使用 http://silviomoreto.github.io/bootstrap-select/ 插件。

如何在所有产品 select all/deselect 时触发事件?我试过 jquery 单击并更改这样的事件:

$(document).on('click','#productCategory', function(event) {
    alert("test");
});

这是我的 Select 列表:

<select id="productCategory" multiple data-actions-box="true">
    <option>Laptop</option>
    <option>Tablet</option>
    <option>Computer</option>
</select>
$(document).ready(function(){
    $("#productCategory").click(function(){
        alert("test");
    });

试试这个代码!

你可以参考这里:http://silviomoreto.github.io/bootstrap-select/options/#events

$('#productCategory').on('changed.bs.select', function (e) {
  // do something...
});

不太明白你的问题。但你想要这样的东西吗?

告诉我

$('#productCategory').selectpicker({
  style: 'btn-info',
  size: 4
});
$(".bs-select-all").on('click', function() {
    alert("ALL SELECTED");
});
$(".bs-deselect-all").on('click', function() {
    alert("ALL DESELECTED");
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js">
</script>
<link href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-select/1.11.2/css/bootstrap-select.min.css" rel="stylesheet"/>
<script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-select/1.11.2/js/bootstrap-select.min.js"></script>
<select id="productCategory" multiple data-actions-box="true">
    <option>Laptop</option>
    <option>Tablet</option>
    <option>Computer</option>
</select>