gpt4 book ai didi

javascript - 时刻 js 的无效日期

转载 作者:行者123 更新时间:2023-11-30 15:44:27 29 4
gpt4 key购买 nike

考虑到这一点 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>

当我尝试拖动左/右 slider (开始/结束值)时,为什么会出现无效日期错误?启动时日期显示正确。当您触摸 slider 时,它会断开。当我将 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,1 对于 (option.max - option.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");
}
});

关于javascript - 时刻 js 的无效日期,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40304483/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com