[英]Want to bind an input field to a jquery-ui slider handle
I want to bind an input field to the jquery-ui slider handle. 我想将输入字段绑定到jquery-ui滑块句柄。 So whenever one value changes I want the other value to also change. 因此,每当一个值发生变化时,我希望另一个值也发生变化。 Ex: if someone types 1000 into the minimum value input field I want the lower slider handle to move to the 1000 mark. 例如:如果有人在最小值输入字段中键入1000,我希望下滑块手柄移动到1000标记。 Also if the user drags the lower slider handle to 1000 the input field should reflect that. 此外,如果用户将下滑块手柄拖动到1000,则输入字段应该反映出来。
Making the slider reflect the changes in the input field is easy: 使滑块反映输入字段中的更改很容易:
$(minYearInput).blur(function () {
$("#yearSlider").slider("values", 0, parseInt($(this).val()));
});
$(maxYearInput).blur(function () {
$("#yearSlider").slider("values", 1, parseInt($(this).val()));
});
I just need help making the text fields mimic the slider. 我只需要帮助使文本字段模仿滑块。
$("#yearSlider").slider({
range: true,
min: 1994,
max: 2011,
step: 1,
values: [ 1994 , 2011 ],
slide: function(event, ui) {
//what goes here?
}
});
Any ideas? 有任何想法吗?
A similar question from this site: Jquery UI Slider - Input a Value and Slider Move to Location 来自此站点的类似问题: Jquery UI Slider - 输入值和滑块移动到位置
Take a careful look at the example code on JQuery UI's page about the range slider . 仔细查看JQuery UI页面上有关范围滑块的示例代码。
You can access the values that the slider has through the ui object. 您可以通过ui对象访问滑块所具有的值。 such as: 如:
function(event, ui) {
//what goes here?
$(minyearInput).val(ui.values[0]);
$(maxyearInput).val(ui.values[1]);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.