设置最小值或最大值后如何刷新jQuery

设置最小值或最大值后如何刷新jQuery

本文介绍了设置最小值或最大值后如何刷新jQuery UI Slider?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个ui.slider并在运行时更改它的最小值和最大值.但是,这些更改仅在以后也设置了值时才会反映在视图中(这会引发不需要的事件).我认为,它也应该在设置min和max之后刷新视图.是否有一个简单的解决方法,似乎滑块缺少一种刷新方法.

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

编辑此问题已在jQuery UI 1.9中得到解决

Edit This issue has been fixed in jQuery UI 1.9

推荐答案

我不知道这是否是jQuery UI滑块中的错误,但是无论如何,您可以做的是更改当前值(从技术上讲,设置将当前值更改为当前值...)以强制刷新视图.遵循文档,这意味着要执行以下操作:

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
});

这篇关于设置最小值或最大值后如何刷新jQuery UI Slider?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-30 15:21