Bootstrap Slider change value handler

后端 未结 4 1393
盖世英雄少女心
盖世英雄少女心 2021-01-04 01:04

I\'m using Bootstrap Slider, and I was wondering if there is any way to include a handler for a value change. I see that the documentation includes handlers for slideStart,

4条回答
  •  星月不相逢
    2021-01-04 01:23

    You can do the following steps:

    1) Use slideStart event to get the original value of your slider

    2) Use slideStop event to get the new value of your slider

    3) Compare this two value, if it's different then fire your code

    var originalVal;
    
    $('.span2').slider().on('slideStart', function(ev){
        originalVal = $('.span2').data('slider').getValue();
    });
    
    $('.span2').slider().on('slideStop', function(ev){
        var newVal = $('.span2').data('slider').getValue();
        if(originalVal != newVal) {
            alert('Value Changed!');
        }
    });
    

    Fiddle Demo

提交回复
热议问题