jquery ui滑块显示值
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11206912/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
jquery ui slider display values
提问by Vince Lowe
I have a slider with values 1 - 5. it updates a hidden input with the ID of 'days'.
我有一个值为 1 - 5 的滑块。它更新了一个 ID 为“天”的隐藏输入。
$(function() {
$("#slider").slider({
value: 3,
min: 1,
max: 5,
step: 1,
slide: function(event, ui) {
$("#days").val(ui.value);
}
});
$("#days").val($("#slider").slider("value"));
});?
I want to add labels to the slider
我想为滑块添加标签
so at position 1 it would say 1 hour, 2 would say 12 hours, 3 would say 1 day, 4 = 3 days and 5 = 1 week.
所以在位置 1 会说 1 小时,2 会说 12 小时,3 会说 1 天,4 = 3 天,5 = 1 周。
but i want to keep the value of days as 1 -5
但我想将天数保持为 1 -5
how is this possible?
这怎么可能?
EDIT
编辑
Want to copy this
想复制这个
回答by tusar
Just arrange your label container (e.g. I added a div
) and when you slide, update it.
只需安排您的标签容器(例如,我添加了一个div
),当您滑动时,更新它。
Live version : http://jsfiddle.net/8ek4a/5/
现场版:http: //jsfiddle.net/8ek4a/5/
Code :
代码 :
$(function() {
var labelArr = new Array("", "1 hour", "12 hours", "1 day", "3 day", "1 week");
$( "#slider" ).slider({
value:3,
min: 1,
max: 5,
step: 1,
slide: function( event, ui ) {
$( "#days" ).val( ui.value );
$("#label").html(labelArr[ui.value]);
}
});
$( "#days" ).val($( "#slider" ).slider( "value" ) );
$("#label").html(labelArr[$( "#slider" ).slider( "value" )]);
});?
UPDATE:Now I have come up with this solution to implement indicator. see http://jsfiddle.net/8ek4a/6/
更新:现在我想出了这个实现指标的解决方案。见http://jsfiddle.net/8ek4a/6/
回答by Marc
you can try this code
你可以试试这个代码
$(function() {
$("#slider-range").slider({
range: true,
min: 12,
max: 500,
values: [ 75, 300 ],
slide: function( event, ui ) {
$( "#amount" ).val( "$" + ui.values[ 0 ] + " - $" + ui.values[ 1 ] );
}
});
$( "#amount" ).val( "$" + $( "#slider-range" ).slider( "values", 0 ) + "- $" + $( "#slider-range" ).slider( "values", 1 ) );
});
回答by Dan
Now we can use this plugin to display values
现在我们可以使用这个插件来显示值
$(".slider").slider().slider("pips", {
first: "pip",
last: "pip"
}).slider("float");
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
<link href="https://code.jquery.com/ui/1.10.4/themes/flick/jquery-ui.css" rel="stylesheet"/>
<link href="https://raw.githubusercontent.com/simeydotme/jQuery-ui-Slider-Pips/master/dist/jquery-ui-slider-pips.min.css" rel="stylesheet"/>
<script src="https://code.jquery.com/ui/1.11.1/jquery-ui.js"></script>
<script src="https://raw.githubusercontent.com/simeydotme/jQuery-ui-Slider-Pips/master/dist/jquery-ui-slider-pips.js"></script>
<div class="slider"></div>