大家好,我是新来的stackoverflow。问题是,我未能从"p"标签的范围滑块中"提取"滑块输出。下面是我的代码:
HTML: <div id="slider" class="range-slider" data-slider data-options="display_selector: #sliderOutput3;">
<span class="range-slider-handle"></span>
<span class="range-slider-active-segment"></span>
</div>
<span id="sliderOutput3"></span>
<p id="qj"></p>
JavaScript: <script>
var element=document.getElementById('slider');
var val = element.getAttribute('data-slider');
document.getElementById("qj").innerHTML=parseInt(val);
</script>
这解决了我的问题:
Jquery变体: $('[data-slider]').on('change.fndtn.slider', function(){
var value = $(this).attr('data-slider');
$('#qj').html(value);
});
纯Javascript:
document.getElementById("slider").onchange = function() {
var value = document.getElementById('slider').getAttribute('data-slider');
document.getElementById('qj').innerHTML=value;
};