引导滑块更改值处理程序 [英] Bootstrap Slider change value handler

查看:15
本文介绍了引导滑块更改值处理程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 Bootstrap Slider,我想知道是否有任何方法可以包含用于更改值的处理程序.我看到文档包含用于 slideStart、slide 和 slideStop 的处理程序,但没有包含用于更改"(价值)的处理程序.

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, slide and slideStop, but none for "change" (of value).

他们可能会滑动滑块并(在释放时)最终达到相同的值,在这种情况下,我不希望事件触发.仅当他们将其滑动到新值时.

It's possible that they could slide the slider around and (upon release) end up on the same value, in which case I would NOT want the event to fire. Only if they slide it to a new value.

我试过了:

$('#sliderAdminType').slider({
    formater: function(value) {
        // my formater stuff that works
        },
    change: function(event, ui) {
        console.log("has changed");
        }       
    });

$('#sliderAdminType').change(function() {
    console.log("has changed");
});

$('#sliderAdminType').slider().change(function() {
    console.log("has changed");
});

$('body').on('change', '#sliderAdminType', function(e){
    console.log("has changed");
});

推荐答案

您可以执行以下步骤:

1) 使用 slideStart 事件获取滑块的原始值

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

2) 使用 slideStop 事件获取滑块的新值

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

3) 比较这两个值,如果不同则触发您的代码

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!');
    }
});

小提琴演示

这篇关于引导滑块更改值处理程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆