我对它的工作原理有点困惑。当滑块处于活动状态时,我试图将秒值转换为输入框中的“hh:mm:ss”。
这里的 div 以秒为单位显示开始时间和结束时间。并在滑动时进行调整
<div class='slider-example col-xs-12 col-sm-6 col-lg-5 center-block'>
<div class="well">
<input id="ex2" type="text" class="span2" value="[{{ start_length }},{{ end_length }}]" data-slider-min="{{ start_length }}" data-slider-max="{{ end_length }}" data-slider-step="1" data-slider-value="[{{ start_length }},{{ end_length }}]" data-slider-selection="after" data-slider-tooltip="hide"/>
</div> <!-- /well -->
</div> <!-- /slider example -->
<div class = "container col-xs-12 col-sm-6 col-lg-5 center-block">
<form class="form-inline">
<div class = "container col-xs-4">
<div class="form-group">
<label for="bar">Start:</label>
<input type="text" class="form-control" id="bar">
</div>
</div>
<div class = "container col-xs-4 pull-right">
<div class="form-group">
<label for="bar1">End: </label>
<input type="text" class="form-control" id="bar1">
</div>
</div>
</form>
</div>
这是我的 javascript
<script type='text/javascript' src="//cdnjs.cloudflare.com/ajax/libs/jquery/2.1.4/jquery.min.js"></script>
<script type='text/javascript' src="{{url_for('static', filename='js/bootstrap-slider.js')}}"></script>
<script type='text/javascript'>
function secondsTimeSpanToHMS(s) {
var h = Math.floor(s/3600);
s -= h*3600;
var m = Math.floor(s/60);
s -= m*60;
return h+":"+(m < 10 ? '0'+m : m)+":"+(s < 10 ? '0'+s : s);
}
$(document).ready(function(){
/* Example 2 */
$("#ex2").slider({});
$("#ex2").on('slide', function (ev) {
$('#bar').val(ev.value.slice(",")[0]);
$('#bar1').val(ev.value.slice(",")[1]);
document.getElementById('#bar').innerHTML = secondsTimeSpanToHMS('#bar');
document.getElementById('#bar1').innerHTML = secondsTimeSpanToHMS('#bar1');
});
});
</script>