[英]Switch programmatically to time view after the date is selected in Tempus Dominus Bootstrap 4 datetimepicker?
How can I switch programmatically to time view after the date is selected in Tempus Dominus Bootstrap 4 datetimepicker?在 Tempus Dominus Bootstrap 4 datetimepicker 中选择日期后,如何以编程方式切换到时间视图?
This is the code:这是代码:
$("#datetimepicker1").on("change.datetimepicker", function (e) {
// After the date is selected, I would like to switch to time view automatically / programmatically
});
I searched in the documentation and the web, but couldn't find an answer.我在文档和 web 中进行了搜索,但找不到答案。 Thank you!
谢谢!
Well,出色地,
though this question is pretty old, I wouldn't say that this is impossible and that it requires modifying the library.尽管这个问题已经很老了,但我不会说这是不可能的,并且需要修改库。
Here is the working code:这是工作代码:
<div class="container" style="padding: 80px;">
<div class="row">
<div class="col-sm-6">
<div class="form-group">
<div class="input-group date" id="datetimepicker1" data-target-input="nearest">
<input type="text" class="form-control datetimepicker-input" data-target="#datetimepicker1" />
<div class="input-group-append" data-target="#datetimepicker1" data-toggle="datetimepicker">
<div class="input-group-text"><i class="fa fa-calendar"></i></div>
</div>
</div>
</div>
</div>
</div>
</div>
$(function() {
$("#datetimepicker1").datetimepicker();
var $picker = $("#datetimepicker1");
$picker.on("change.datetimepicker", function (e) {
// After the date is selected, I would like to switch to time view automatically / programmatically
if (!e.oldDate && $picker.datetimepicker('useCurrent')) {
// First time ever. If useCurrent option is set to true (default), do nothing
// because the first date is selected automatically.
return;
}
else if (
e.oldDate &&
e.date &&
(e.oldDate.format('YYYY-MM-DD') === e.date.format('YYYY-MM-DD'))
) {
// Date didn't change (time did).
return;
}
setTimeout(function () {
$('#datetimepicker1 [data-action="togglePicker"]').click();
}, 300); // With a mini delay so that the animation doesn't fire right-away.
});
});
Here is the working JSFiddle .这是工作的JSFiddle 。
I hope this helps you.我希望这可以帮助你。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.