Bootstrap-select - how to fire event on change

后端 未结 6 1399
隐瞒了意图╮
隐瞒了意图╮ 2020-12-08 09:30

I\'m using Bootstrap 3.0.2 and the Bootstrap-select plugin.

Here\'s my select list:



        
6条回答
  •  死守一世寂寞
    2020-12-08 10:07

    When Bootstrap Select initializes, it'll build a set of custom divs that run alongside the original

Solution 2 - Bootstrap Select Custom Events

As this answer alludes, Bootstrap Select has their own set of custom events, including changed.bs.select which:

fires after the select's value has been changed. It passes through event, clickedIndex, newValue, oldValue.

And you can use that like this:

$("select").on("changed.bs.select", 
      function(e, clickedIndex, newValue, oldValue) {
    console.log(this.value, clickedIndex, newValue, oldValue)
});

Demo in Stack Snippets:

$(function() {

  $("select").on("changed.bs.select", 
        function(e, clickedIndex, newValue, oldValue) {
      console.log(this.value, clickedIndex, newValue, oldValue)
  });

});






提交回复
热议问题