seiyria/bootstrap-slider getValue() not working

末鹿安然 提交于 2019-12-25 07:20:35

问题


I've looked through all the answers on this topic, but for some reason I can't get it to work. I've set up a slider with the following markup:

<input data-slider-id="Xslide" type="text" data-provide="slider" data-slider-min="0" data-slider-max="10" data-slider-step=".5" data-slider-value="0" data-slider-tooltip="show" data-slider-orientation="vertical" data-slider-reversed="true"></input>

What I want first of all is to console.log its numerical value. I've tried playing with the type to number or text but that didn't work. I tried as per the example on GitHub:

var mySlider = $("Xslide").slider();
var value = mySlider.slider('getValue');
console.log(value);

but that produced the error $(...).getValue is not a function

I tried writing $('#Xslide').data('slider').getValue() but that produced the error $(...).data(...) is undefined.

I tried solutions offered on the example page like

$('#Xslide').slider({
    formatter: function(value) {
        console.log('Current value: ' + value);
    }
});

but that just doesn't show anything in the console at all..

I've included the following js and css files:

<script src="js/bootstrap-slider.min.js"></script>
<link href="stylesheets/bootstrap-slider.min.css" rel="stylesheet">

Not sure why it isn't working... perhaps it's something about the input element id or the type, but any help would be appreciated.


回答1:


In any case so far I've solved it using:

var Xslide = new Slider('#Xslide'); 

Xslide.on('slideStop', function (value) { document.getElementById('xval').innerHTML = value; 
})

Thanks!



来源:https://stackoverflow.com/questions/38825650/seiyria-bootstrap-slider-getvalue-not-working

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!