How to refresh a jQuery UI Slider after setting mi

2019-01-22 18:30发布

I have a ui.slider and change it's min and max values on runtime. But these changes only get reflected in the view, when I set the values afterwards too (which causes it to fire events that are not needed). In my opinion, it should refresh the view after setting min and max too. Is there a simple workaround, seems like a refresh method is missing for the slider.

$("#something").slider({
    range: true,
    values: [25, 75],
    min: 0,
    max: 100
});
$("#something").slider("option", "min", 25); // left handle should be at the left end, but it doesn't move
$("#something").slider("option", "values", [25, 75]); // the left handle is now at the left end, but doing this triggers events

Edit This issue has been fixed in jQuery UI 1.9

8条回答
我命由我不由天
2楼-- · 2019-01-22 18:55

It could be a version issue but nothing I tried with options "min / max" worked. This is OK and tested with JQuery UI 1.10. This way you can use either the slider or the numbers to change the other one:

$("#mySlider").slider({range: true, min: 0, max: 100, values: [ 0, 100 ], step: 10,
   slide: function( event, ui ) {
      $("#mySliderMin").val( ui.values[ 0 ]);
      $("#mySliderMax").val( ui.values[ 1 ]);
   }
});
$("#mySliderMin").val($("#mySlider").slider( "values", 0 ));
$("#mySliderMax").val($("#mySlider").slider( "values", 1 ));
$("#mySliderMin, #mySliderMax").change(function () {
   $("#mySlider").slider("values", 0, $("#mySliderMin").val());
   $("#mySlider").slider("values", 1, $("#mySliderMax").val());
});
查看更多
一夜七次
3楼-- · 2019-01-22 19:04

You can update the html div in jquery function as

var d='<div class="row grid_slider"><div><p>Grid With time in 24 hour format</p><input type="text" class="range_time24" value="" name="range" /></div></div>';document.getElementById("slider").innerHTML=d;

Then set new values to slider

查看更多
Lonely孤独者°
4楼-- · 2019-01-22 19:07

Setting the minimum slider value like:

$slide.slider("option", "min", 25); does not work for me.

Instead I used: $slide.slider("values", "0", 25); and everything is working fine.

For setting the maximum slider value, use $slide.slider("values", "1", 75);

For more information on setting values, see the api docs - http://api.jqueryui.com/slider/#option-values

查看更多
神经病院院长
5楼-- · 2019-01-22 19:08

You need to keep a reference to your slider object,

var slider = $("#something").slider({
               range: true,
               values: [25, 75],
               min: 0,
               max: 100
             });
slider.slider("option", "min", 25);

This is all listed in the Documentation

查看更多
太酷不给撩
6楼-- · 2019-01-22 19:10

I don't know whether this is a bug in the jQuery UI slider, but anyway, what you can do is change the current value (technically, setting the current value to the current value...) to force the view to be refreshed. Following the documentation, this would mean doing something like this :

$(function() { 
    var $slide = $("#something").slider({
        range: true,
        values: [25, 75],
        min: 0,
        max: 100
    });
    $slide.slider("option", "min", 25); // left handle should be at the left end, but it doesn't move
    $slide.slider("value", $slide.slider("value")); //force the view refresh, re-setting the current value
});  
查看更多
走好不送
7楼-- · 2019-01-22 19:15

Please try this:

$("#Slider2").slider("value", 10, 1000); //10 = min and 1000 = max 
查看更多
登录 后发表回答