2014-02-27 88 views
0

我想配置一個滑塊來顯示多個值,其中一個是標準數字輸出,另一個是數組中值的輸出。Jquery UI滑塊,多值輸出

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

我想在手柄中的值是標準1-100但值的下面,以與定製陣列,我將限定相對應。

換句話說,我怎麼會鏈接

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

到出來的東西像一個數組:

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

等?

+0

什麼是對的陣列,並且其中的代碼在你的提琴應顯示從它的價值? – j08691

+0

你試過用字典嗎?例如。 '{1:15,2:23,...}' – Zhihao

+0

請您詳細說明一下嗎? – YKB

回答

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

+0

優秀,正是我所需要的! – YKB

+0

很高興幫助。 – aaronfay