问题
When I do
console.log($('#my_slider').slider('value'))
it returns [object Object] Does anyone know why it doesn't return the actual value of the slider like it says it is supposed to in the documentation?
回答1:
You should use (here doc)
console.log($('#my_slider').slider( "option", "value" ))
回答2:
This is to allow method chaining.
http://www.jquery-tutorial.net/introduction/method-chaining/#.UHqPHMXLSKg
The returned object that you are seeing is the original matched set (#my_slider). So, if you had other jQuery methods to call on this you could add them to the end of your statement.
$('#my_slider').slider('value').othermethod();
回答3:
This works for .draggable and should work for .slider too
$(function() {
$( "#slider" ).slider(
stop: function (s) {
console.log(s);
}
);
});
回答4:
This code works for me on the demo page for slider:
$('#slider').slider('value');
Here: http://jqueryui.com/resources/demos/slider/hotelrooms.html
Might want to look at your implementation.
来源:https://stackoverflow.com/questions/12881198/why-does-the-jquery-ui-slider-return-an-object