HH:mm 格式的离子范围滑块从和到不工作
Ion Range Slider with HH:mm format From & To not working
我正在尝试在我的项目中使用 Ion Range Slider 以 select 工作时间。例如:(08:00-19:00).
$('#ion').ionRangeSlider({
grid: false,
type: 'double',
min: moment("0000", "hhmm"),
max: moment("2359", "hhmm"),
from: moment("0800", "hhmm"),
to: moment("1900", "hhmm"),
force_edges: true,
drag_interval: true,
step: 3600000,
min_interval: 3600000,
prettify: function (num) {
return moment(num).format('HH:mm');
}
});
当我想使用 from & to 设置默认工作时间时,它不起作用。虽然滑块有效,但值没有改变。
我错过了什么?
因为您使用的是以毫秒为单位的小时,所以您需要将您正在使用的 moment 的值从一个对象更改为它的毫秒值:
min: moment("0000", "hhmm"), // this is an object and not a number...
max: moment("2359", "hhmm"),
from: moment("0800", "hhmm"),
to: moment("1900", "hhmm"),
更改为(请参阅 details 的文档):
min: moment("0000", "hhmm").valueOf(),
max: moment("2359", "hhmm").valueOf(),
from: moment("0800", "hhmm").valueOf(),
to: moment("1900", "hhmm").valueOf(),
$('#ion').ionRangeSlider({
grid: false,
type: 'double',
min: moment("0000", "hhmm").valueOf(),
max: moment("2359", "hhmm").valueOf(),
from: moment("0800", "hhmm").valueOf(),
to: moment("1900", "hhmm").valueOf(),
force_edges: true,
drag_interval: true,
step: 3600000,
min_interval: 3600000,
prettify: function (num) {
return moment(num).format('HH:mm');
}
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.14.1/moment.min.js"></script>
<link rel="stylesheet" href="https://rawgit.com/IonDen/ion.rangeSlider/master/css/ion.rangeSlider.css">
<link rel="stylesheet" href="https://rawgit.com/IonDen/ion.rangeSlider/master/css/ion.rangeSlider.skinModern.css">
<script src="https://rawgit.com/IonDen/ion.rangeSlider/master/js/ion.rangeSlider.min.js"></script>
<input type="text" id="ion" name="example_name" value="" />
我正在尝试在我的项目中使用 Ion Range Slider 以 select 工作时间。例如:(08:00-19:00).
$('#ion').ionRangeSlider({
grid: false,
type: 'double',
min: moment("0000", "hhmm"),
max: moment("2359", "hhmm"),
from: moment("0800", "hhmm"),
to: moment("1900", "hhmm"),
force_edges: true,
drag_interval: true,
step: 3600000,
min_interval: 3600000,
prettify: function (num) {
return moment(num).format('HH:mm');
}
});
当我想使用 from & to 设置默认工作时间时,它不起作用。虽然滑块有效,但值没有改变。
我错过了什么?
因为您使用的是以毫秒为单位的小时,所以您需要将您正在使用的 moment 的值从一个对象更改为它的毫秒值:
min: moment("0000", "hhmm"), // this is an object and not a number...
max: moment("2359", "hhmm"),
from: moment("0800", "hhmm"),
to: moment("1900", "hhmm"),
更改为(请参阅 details 的文档):
min: moment("0000", "hhmm").valueOf(),
max: moment("2359", "hhmm").valueOf(),
from: moment("0800", "hhmm").valueOf(),
to: moment("1900", "hhmm").valueOf(),
$('#ion').ionRangeSlider({
grid: false,
type: 'double',
min: moment("0000", "hhmm").valueOf(),
max: moment("2359", "hhmm").valueOf(),
from: moment("0800", "hhmm").valueOf(),
to: moment("1900", "hhmm").valueOf(),
force_edges: true,
drag_interval: true,
step: 3600000,
min_interval: 3600000,
prettify: function (num) {
return moment(num).format('HH:mm');
}
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.14.1/moment.min.js"></script>
<link rel="stylesheet" href="https://rawgit.com/IonDen/ion.rangeSlider/master/css/ion.rangeSlider.css">
<link rel="stylesheet" href="https://rawgit.com/IonDen/ion.rangeSlider/master/css/ion.rangeSlider.skinModern.css">
<script src="https://rawgit.com/IonDen/ion.rangeSlider/master/js/ion.rangeSlider.min.js"></script>
<input type="text" id="ion" name="example_name" value="" />