0

It would be great if you could help me with a problem.

I'm using Bootstrap Slider (https://seiyria.com/bootstrap-slider/).

I want to display the Current Slider Value.

It works with the comma. How can I change the ',' -> ' to '

Age Range ...<br/>
<b>18</b> &nbsp; &nbsp;  <span><input id="ex2" type="text" class="span2" value="" data-slider-min="18" data-slider-max="100" data-slider-step="1" data-slider-value="[30,55]"/></span> &nbsp; &nbsp; <b>100</b><br/>
<span id="ageSliderLabel">Current Slider Value: <span id="ageSliderVal">30,55</span></span>


	<!-- Bootstrap Slider -->
	<link href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-slider/10.2.1/css/bootstrap-slider.css" rel="stylesheet">	
	<script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-slider/10.2.1/bootstrap-slider.js"></script>		
	
	<script>
		var slider = new Slider('#ex2', {});
		slider.on("slide", function(sliderValue) {
			document.getElementById("ageSliderVal").textContent = sliderValue; 
		});		
	</script>

4

3 回答 3

2
document.getElementById("ageSliderVal").textContent = sliderValue.replace(",", " to ")

https://www.w3schools.com/jsref/jsref_replace.asp

于 2018-10-28T08:13:55.830 回答
0

我有解决办法。

它在使用 toString() 后工作

    <script>
    var slider = new Slider('#ex2', {});
    slider.on("slide", function(sliderValue) {
        var sliderValue = sliderValue.toString();
        document.getElementById("ageSliderVal").textContent = sliderValue.replace(",", " to ")
    });     
</script>
于 2018-10-28T10:49:36.203 回答
0

不幸的是,它对我不起作用。

我必须在 php 中将代码与反斜杠集成,然后就没有任何效果了。

var slider = new Slider('#ex2', {}); slider.on(\"slide\", function(sliderValue) { document.getElementById(\"ageSliderVal\").textContent = sliderValue.replace(\",\", \" to \") });

于 2018-10-28T08:24:35.223 回答