【问题标题】:I want my jQueryUI range slider to move dynamically depending on the input value我希望我的 jQueryUI 范围滑块根据输入值动态移动
【发布时间】:2019-04-26 08:18:11
【问题描述】:

here is the range slider

基本上,当我更改输入中的数字时,我希望我的滑块移动。

HTML 代码:

<input id="txtMinPrice" type="text" placeholder="de la">
<input id="txtMaxPrice" type="text" placeholder="pana la">
<div id="price__range"></div>

jQuery 代码:

`var sliderElement = $('#price__range');
$("#price__range").slider({
  range: true,
  min: 0,
  max: 100,
  values: [ 35, 100 ],
  slide: function(event, ui) {
    $('#txtMinPrice').val(ui.values[0]);
    $('#txtMaxPrice').val(ui.values[1]);
  }
});
$('#txtMinPrice').val(sliderElement.slider('values', 0));
$('#txtMaxPrice').val(sliderElement.slider('values', 1));`

【问题讨论】:

    标签: html jquery-ui rangeslider


    【解决方案1】:
    $('#txtMinPrice, #txtMaxPrice').on({
        'input change': function(){
             $("#price__range").slider("option", "min", $('#txtMinPrice').val());
             $("#price__range").slider("option", "max", $('#txtMaxPrice').val());
             $('#price__range').slider( "option", "value", $('#price__range').slider("value"));
        }
    })
    

    基本上,您可以在输入上侦听inputchange 事件,您可以根据需要对其进行修改,然后继续替换滑块的最小值和最大值。来自docs

    【讨论】:

    • 没有抛出任何错误,只是当我在输入中输入任何数字时,两个滑块圈都向左移动,之后它们就不动了
    • 我的错,我忘了更新值。我已经更新了代码。它现在应该可以工作了。
    • 还是同样的问题:\
    猜你喜欢
    • 1970-01-01
    • 2019-01-07
    • 1970-01-01
    • 2019-03-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多