jQuery UI滑块显示值 [英] jquery ui slider display values

查看:77
本文介绍了jQuery UI滑块显示值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个值为1-5的滑块.它会更新ID为'days'的隐藏输入.

I have a slider with values 1 - 5. it updates a hidden input with the ID of 'days'.

$(function() {
    $("#slider").slider({
        value: 3,
        min: 1,
        max: 5,
        step: 1,
        slide: function(event, ui) {
            $("#days").val(ui.value);
        }
    });
    $("#days").val($("#slider").slider("value"));
});​

我想在滑块上添加标签

所以在位置1会说1小时,2会说12小时,3会说1天,4 = 3天,5 = 1周.

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 -5

but i want to keep the value of days as 1 -5

这怎么可能?

编辑

想要复制此内容

推荐答案

只需安排您的标签容器(例如,我添加了div),并在滑动时对其进行更新.

Just arrange your label container (e.g. I added a div) and when you slide, update it.

实时版本: http://jsfiddle.net/8ek4a/5/

代码:

$(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" )]);
});​

更新: 现在,我想出了实现指标的解决方案.参见 http://jsfiddle.net/8ek4a/6/

UPDATE: Now I have come up with this solution to implement indicator. see http://jsfiddle.net/8ek4a/6/

这篇关于jQuery UI滑块显示值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆