简体   繁体   English

带有日期js的无效日期

[英]Invalid Date with moment js

Considering this http://jsfiddle.net/2a0hsj4z/4/ , here as a snippet: 考虑到此http://jsfiddle.net/2a0hsj4z/4/ ,此处为摘要:

 moment.locale("en"); var start = moment("2010-10", "YYYY-MM"); var end = moment("2017-10", "YYYY-MM"); $("#chord_range").ionRangeSlider({ type: "double", grid: true, min: start.format("x"), max: end.format("x"), from: start.format("x"), to: end.format("x"), prettify: function (num) { return moment(num, 'x').format("MMMM YYYY"); } }); var slider = $("#chord_range").data("ionRangeSlider"); $(".irs-slider").click(function() { console.log(slider.result.from); }) 
 <link href="http://ionden.com/a/plugins/ion.rangeSlider/static/css/skin2.css" rel="stylesheet"/> <link href="http://ionden.com/a/plugins/ion.rangeSlider/static/css/ion.rangeSlider.css" rel="stylesheet"/> <input id="chord_range" /> <script src="http://code.jquery.com/jquery-1.11.0.js"></script> <script src="http://ionden.com/a/plugins/ion.rangeSlider/static/js/ion-rangeSlider/ion.rangeSlider.js"></script> <script src="http://momentjs.com/downloads/moment.min.js"></script> 

Why do I get an Invalid Date error when I try to drag the left/right slider (start/end value)? 当我尝试向左/向右滑动滑块(开始/结束值)时,为什么会收到“ Invalid Date error On startup the date shows correctly. 在启动时,日期显示正确。 When you touch the slider, it breaks. 当您触摸滑块时,它会断裂。 When I replace var start = moment("2010-10", "YYYY-MM"); 当我替换var start = moment("2010-10", "YYYY-MM"); with var start = moment("2012-10", "YYYY-MM"); 使用var start = moment("2012-10", "YYYY-MM"); it works: 有用:

 moment.locale("en"); var start = moment("2012-10", "YYYY-MM"); var end = moment("2017-10", "YYYY-MM"); $("#chord_range").ionRangeSlider({ type: "double", grid: true, min: start.format("x"), max: end.format("x"), from: start.format("x"), to: end.format("x"), prettify: function (num) { return moment(num, 'x').format("MMMM YYYY"); } }); var slider = $("#chord_range").data("ionRangeSlider"); $(".irs-slider").click(function() { console.log(slider.result.from); }) 
 <link href="http://ionden.com/a/plugins/ion.rangeSlider/static/css/skin2.css" rel="stylesheet"/> <link href="http://ionden.com/a/plugins/ion.rangeSlider/static/css/ion.rangeSlider.css" rel="stylesheet"/> <input id="chord_range" /> <script src="http://code.jquery.com/jquery-1.11.0.js"></script> <script src="http://ionden.com/a/plugins/ion.rangeSlider/static/js/ion-rangeSlider/ion.rangeSlider.js"></script> <script src="http://momentjs.com/downloads/moment.min.js"></script> 

Why is that? 这是为什么?

you miss the step option and step will be 1, 1 is too small for (option.max - option.min) and will cause error in ion rangeSlider.So you should set a large number for step option. 您错过了step选项,并且step将为1,step(max.option -min.min)太小,将导致ion rangeSlider错误。

$("#chord_range").ionRangeSlider({
    type: "double",
    grid: true,
    min: start.format("x"),
    max: end.format("x"),
    from: start.format("x"),
    to: end.format("x"),
    step: 100000,
    prettify: function (num) {
      return moment(num, 'x').format("MMMM YYYY");
    }
}); 

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

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