Jquery ionslider 上的更改功能不起作用

Jquery change function on ionslider not working

我的项目中有一个 ionslider。我需要预测滑块的变化。 这是我的滑块

$("#myslider").ionRangeSlider();

关于更改函数

$("#myslider").on('change',function(){
    var $this = $(this),
    from = $this.data("from"),
    to = $this.data("to");

   console.log(from + " - " + to);
});

但是'change'功能不工作。这是预测滑块变化的正确方法吗?或者有什么办法..谢谢

您应该使用 ionRangeSlider 的 onChange 事件:

$("#range_43").ionRangeSlider({
    type: "single",
    min: 0,
    max: 100,
    from: 50,
    keyboard: true,
    onStart: function(data) {
        console.log("onStart");
    },
    onChange: function(data) {
        console.log("onChange");
    },
    onFinish: function(data) {
        console.log("onFinish");
    },
    onUpdate: function(data) {
        console.log("onUpdate");
    }
});

http://ionden.com/a/plugins/ion.rangeSlider/demo_interactions.html

你可以使用这个:

$("#myslider").change(function(){
    console.log("check"); //check if it successfully enters .change function
    var $this = $(this),
    from = $this.data("from"),
    to = $this.data("to");

   console.log(from + " - " + to);
});

如果第二个控制台日志没有继续,您的变量值可能有问题。 .change 应该由 .ionRangeSlider()

触发