Why does the jquery ui slider return an object?

谁都会走 提交于 2019-12-10 19:52:52

问题


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

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