Jquery UI Slider,多值输出

时间:2014-02-27 19:44:43

标签: javascript jquery html css jquery-ui

我正在尝试配置滑块以显示多个值,其中一个是标准数字输出,另一个是数组中值的输出。

http://jsfiddle.net/YKBRWC/7B5jK/1/

我希望句柄中的值是标准的1-100,但下面的值与我要定义的自定义数组相对应。

换句话说,我将如何链接

$("#amount").html(value);

输出类似的数组:

[1=15,2=23,3=26,4=32,5=39]

等?

1 个答案:

答案 0 :(得分:2)

你是说这样的意思吗?

http://jsfiddle.net/EvPTj/5/

var ageInput = $("#ageInput"),
    initialValue = 1,
    values = [];

values = ['',15,23,26,32,39,15,23,26,32,39,15,23,26,32,39,15,23,26,32,39,15,23,26,32,39,15,23,26,32,39,15,23,26,32,39,15,23,26,32,39,15,23,26,32,39,15,23,26,32,39,15,23,26,32,39,15,23,26,32,39,15,23,26,32,39,15,23,26,32,39,15,23,26,32,39,15,23,26,32,39,15,23,26,32,39,15,23,26,32,39,15,23,26,32,39,15,23,26,32,39];

var updateSliderValue = function (e, ui) {
    var slider = $(this).data().slider;
    var index = ui.value || 0;
    if (index) {
        $("#amount").html(index + "=" + values[index]);
        slider.element.find(".ui-slider-handle").text(slider.value());
    }
};

var value = $("#slider").slider("value");
$("#amount").html(value);


ageInput.slider({
    min: 0,
    max: 100,
    slide: updateSliderValue,
    create: updateSliderValue,
    value: initialValue
});

AF