【发布时间】:2021-05-08 05:14:34
【问题描述】:
我的目标是用户可以通过两种方式调整 Belopp,通过输入字段或通过滑块。后者现在正在工作,所以一个问题还没有解决。
我希望我的滑块根据输入字段中输入的值进行调整
在屏幕截图中,Belopp 的值为 40。但范围滑块仍在中间。因为输入的值是40,所以它应该在最左边是不正确的。
我的 HTML:
<div class="col-12 mx-auto ">
<div class="slider-wrapper slider-ghost">
<input class="input-range"
id='priceSlider'
type="text"
data-slider-min="40"
data-slider-tooltip="hide"
data-slider-max="120"
data-slider-step="1"
data-slider-value=""
/>
</div>
</div>
和我的 JS,我已经将滑块的值分配给 newBeloppValue 但范围滑块不会移动。
$(document).ready(function () {
$("#belopp").change(function () {
let newBeloppValue = parseFloat($("#belopp").val());
if ($("#belopp").val().length > 0) {
// belopp value should not be lower or higher than the minmax range
if (newBeloppValue < minValue || newBeloppValue > maxValue) {
console.log("error");
} else {
//value of slider should get the input value
$("#priceSlider").slider({
value: newBeloppValue,
});
}
}
});
$("#priceSlider").slider();
$("#priceSlider").on("slide", function (slideEvt) {
// slider value will be displayed on the belopp input
$("#belopp").val(slideEvt.value);
});
}); })
我在这里错过了什么?
【问题讨论】:
标签: jquery input slider range bootstrap-slider