Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
522 views
in Technique[技术] by (71.8m points)

Bootstrap range slider with displayed values

I checked Bootstrap 4 documentation for the range slider and answers here on SO, but can't find a way for the slider to display the value when the track is being moved.

enter image description here

I see open-source projects like seiyria/bootstrap-sliderand which allow you to do that, but is there really no built-in way (bootstrap parameter) to display values when the track is moved?

question from:https://stackoverflow.com/questions/65856695/bootstrap-range-slider-with-displayed-values

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Answer is no, there is no default way.

My workaround is below. After looking at a bunch of solutions and noticing how incosistent they are across browsers devices decided that it's best to just output the selection in real time in a div container.

Slider HTML:

<div class="form-group mt-4 text-center">
<label for="price"><h4>Minimum price</h4></label>

<div class="price">500000</div>
<input type="range" class="custom-range" min="20000" max="1000000" step="10000" id="customRange3" name="Price" value="500000" style="width: 100%">

This will output in real time the currently selected range inside a div contained (requires jquery)

<script>
$( document ).ready(function() {
    $('#customRange3').on('input', function(){
         v = $('#customRange3').val();
         console.log(v);
         $('div.price').text(v);
    });
});
</script>

Now, as you slide the tracker up and down it will update the number below 'Result' enter image description here


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

57.0k users

...