动态设置Bootstrap滑块的值?

时间:2015-11-02 09:26:10

标签: javascript jquery twitter-bootstrap slider

我创建了一个滑块,如下所示

<input id="brightness" onChange="changeBrightness()" data-slider-id='ex1Slider' type="text"
                    data-slider-min="-100" data-slider-max="100" data-slider-step="2" data-slider-value="0"/>

我需要动态设置值到此滑块。我试过了,

$("#brightness").slider('setValue', 8, true);
$("#brightness").slider('refresh');

但这不起作用。我该怎么办?

3 个答案:

答案 0 :(得分:6)

$("#brightness").slider('setValue', 8, true);

刷新初始值 $("#brightness").slider('refresh');

答案 1 :(得分:4)

尝试以下脚本:

$(window).load(function() {
    $("#brightness").attr('data-slider-value', 8);
    $("#brightness").slider('refresh');
});

答案 2 :(得分:3)

您可以动态地对滑块值进行以下几项操作:jsfiddle

var slider = new Slider("#budget-slider-1");
var slider2 = new Slider("#budget-slider-2");

slider.on("change", function(slideEvent) {
  var currentValueSlider2 = slider2.getValue();
  slider2.options.min = 80;
  slider2.setValue(100);
});