jQuery UI 滑块(以编程方式设置) [英] jQuery UI Slider (setting programmatically)

查看:27
本文介绍了jQuery UI 滑块(以编程方式设置)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想即时修改滑块.我尝试使用

I'd like to modify the sliders on-the-fly. I tried to do so by using

$("#slider").slider("option", "values", [50,80]);

此调用将设置值,但元素不会更新滑块位置.打电话

This call will set the values, but the element will not update the slider positions. Calling

$("#slider").trigger('change');

也无济于事.

是否有另一种/更好的方法来修改值和滑块位置?

Is there another/better way to modify the value AND slider position?

推荐答案

这取决于你是想改变当前范围内的滑块还是改变滑块的范围.

It depends on if you want to change the sliders in the current range or change the range of the sliders.

如果你想改变当前范围内的值,那么 .slider() 方法是你应该使用的方法,但语法与你使用的有点不同:

If it is the values in the current range you want to change, then the .slider() method is the one you should use, but the syntax is a bit different than you used:

$("#slider").slider('value',50);

或者如果您有一个带有两个手柄的滑块,它将是:

or if you have a slider with two handles it would be:

$("#slider").slider('values',0,50); // sets first handle (index 0) to 50
$("#slider").slider('values',1,80); // sets second handle (index 1) to 80

如果是您要更改的范围,则为:

If it is the range you want to change it would be:

$("#slider").slider('option',{min: 0, max: 500});

这篇关于jQuery UI 滑块(以编程方式设置)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆