0

我正忙于构建一个 javascript 类来自动创建 Jquery UI 滑块。

    CustomSlider.prototype.initialize = function(slider_id, min_id, max_id, step, min, max){
        this.$slider = $('#' + slider_id);
        this.$min = $('#' + min_id);
        this.$max = $('#' + max_id);
        this.min = min;
        this.max = max;
        this.step = step;

        this.$slider.slider({
            range: true,
            step: this.step,
            min: this.min,
            max: this.max,
            values: [(this.min + (step * 4)), (this.max - (step * 4))],
            slide: this.slide(event, ui)
        });

        this.$min.text(this.min + (step * 4));
        this.$max.text(this.max - (step * 4));
    };

    CustomSlider.prototype.slide = function(event, ui){
        this.$min.text(ui.values[0]);
        this.$max.text(ui.values[1]);
    };

当我尝试绑定幻灯片事件时,它不会使用“event”和“ui”变量。如何将此事件绑定到我自己的函数?

4

1 回答 1

3

应该只是

    this.$slider.slider({
        range: true,
        step: this.step,
        min: this.min,
        max: this.max,
        values: [(this.min + (step * 4)), (this.max - (step * 4))],
        slide: this.slide
    });

您需要将函数引用分配为slide属性的值。

在您的情况下,您调用该this.slide函数将其返回的值分配给 slide 属性,在这种情况下为 undefined

于 2013-06-19T09:52:46.827 回答