简体   繁体   English

如何从jQuery范围滑块获取值

[英]How to get values from jquery range slider

I'm using ui jquery slider, but i'm not able to get the value. 我正在使用ui jquery滑块,但无法获取该值。

 $("#ex1").slider({ value: 1400, min: 1400, max: 12000, step: 20, slide: function(event, ui) { $("#slider-value").html(ui.value); } }); $("#slider-value").html($('#ex1').slider('value')); 
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/jqueryui/1.12.1/jquery-ui.min.js"></script> <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/jqueryui/1.12.1/jquery-ui.min.css" /> <input id="ex1" data-slider-id='ex1Slider' type="range" data-slider-min="1400" data-slider-max="12000" data-slider-step="20" data-slider-value="0" /><b class="price-left"> <span id="slider-value"></span> 

Can anyone help me with this? 谁能帮我这个?

Your issue is because you're instantiating the slider() on a input type="range" element. 您的问题是因为您要在input type="range"元素上实例化slider() It should be used with a plain div . 它应与普通div一起使用。 Change that and the rest of your code works fine: 更改它,其余代码工作正常:

 $("#ex1").slider({ value: 1400, min: 1400, max: 12000, step: 20, slide: function(event, ui) { $("#slider-value").html(ui.value); } }); $("#slider-value").html($('#ex1').slider('value')); 
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/jqueryui/1.12.1/jquery-ui.min.js"></script> <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/jqueryui/1.12.1/jquery-ui.min.css" /> <div id="ex1" data-slider-id='ex1Slider' data-slider-min="1400" data-slider-max="12000" data-slider-step="20" data-slider-value="0"></div> <span id="slider-value"></span> 

The slider documentation has full explanations of all other methods and properties you can use. 滑块文档全面说明了您可以使用的所有其他方法和属性。

 $('#ex1').slider("option", "value");

您可以尝试这个(y)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM