簡體   English   中英

帶有日期js的無效日期

[英]Invalid Date with moment js

考慮到此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> 

當我嘗試向左/向右滑動滑塊(開始/結束值)時,為什么會收到“ Invalid Date error 在啟動時,日期顯示正確。 當您觸摸滑塊時,它會斷裂。 當我替換var start = moment("2010-10", "YYYY-MM"); 使用var start = moment("2012-10", "YYYY-MM"); 有用:

 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> 

這是為什么?

您錯過了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