【问题标题】:How to initialize default values in jQuery slider?如何在 jQuery 滑块中初始化默认值?
【发布时间】:2015-09-27 22:04:41
【问题描述】:

我正在使用jQRangeSlider 制作一个显示日期的简单滑块。 我阅读了here 的解释(只阅读第一部分,无需阅读整个页面......)现在想用默认值制作一个简单的“Hello world”:

  • 滑块范围 Jan-2014...Jun-2014
  • 默认情况下,标记放置在 4 月 1 日和 4 月 25 日(4 月 = 3 月)。

这是我的代码:

<!DOCTYPE>
  <html>
  <head>
        <meta charset="utf-8"/>         
        <link rel="stylesheet" href="css/iThing.css" type="text/css" />
  </head>
  <body>
        <h1>Hello world</h1>
        <div id="slider"></div>
        <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
        <script src="jquery-ui.js"></script>            
        <script src="jQDateRangeSlider-min.js"></script>



        <script>

            //create the slider
            $("#slider").dateRangeSlider();

            //set options - the the bounds of the slider
            $("#slider").dateRangeSlider(
                      "option",
                      "bounds",
                      {
                        min: new Date(2014, 1, 1),
                        max: new Date(2014, 5, 25)  
                    });

            //set options - the the boundsdefault values of the slider                                                              
            $("#slider").dateRangeSlider(
                      "option",
                      "defaultValues",
                      {
                        min: new Date(2014, 3, 1),
                        max: new Date(2014, 3, 25)  
                    });




        </script>
</body>
</html>

我确实看到了 slier,它正在工作,但没有使用正确的值进行初始化。

看起来很简单,但是滑块没有正确初始化。我怎样才能解决这个问题?谢谢!

【问题讨论】:

  • 我知道这是否只是为了您的示例,但您似乎在同一元素上分别初始化 dateRangeSlider 3 次。
  • 我写的文档是这样设置选项的,所以我设置了好几次......不是吗?我该怎么办?谢谢!
  • 我写了这个并初始化了月份范围: $("#slider").dateRangeSlider({ bounds: { min: new Date(2014, 1, 1) , max: new Date(2014) , 5, 25) } });
  • 抱歉。意识到我所说的不适用于您正在使用的插件。我在下面的回答是我的想法,而不是在初始化后设置选项。希望对您有所帮助!

标签: jquery jquery-ui jquery-plugins slider


【解决方案1】:

这可能对你有用。我只是立即初始化选项。

 $("#slider").dateRangeSlider(
            bounds:
                   {
                      min: new Date(2014, 1, 1),
                      max: new Date(2014, 5, 25)  
                   },
            defaultValues:
                   {
                      min: new Date(2014, 3, 1),
                      max: new Date(2014, 3, 25)
                   } 
    );

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-12-29
    • 2020-02-08
    • 1970-01-01
    • 1970-01-01
    • 2015-02-25
    相关资源
    最近更新 更多