日期时间选择器:重置
Date time picker : Reset
我正在使用 package. Specifically ThIS。
一切正常,我点击日期选择器,选择年份,然后选择月份,然后选择日期,然后选择器关闭。
但是当它关闭时我再次点击它,只有最后一天的日历显示,这意味着它不会从一年开始重新开始。
我要的是,年复一年,月复一日,重新开始。
这里是JsFiddle
这是我的代码:
<div class='input-group date' id='datetimepicker9'>
<input type='text' class="form-control" />
<span class="input-group-addon">
<span class="glyphicon glyphicon-calendar"></span>
</span>
</div>
Js :
$(function () {
$('#datetimepicker9').datetimepicker({
viewMode: 'years'
});
});
您可以重置 viewMode
using dp.hide
事件和 setTimeout
let $datePicker = $('#myDatepicker').datetimepicker({
useCurrent: false,
viewMode: 'years'
});
$datePicker.on('dp.hide', function(event) {
setTimeout(function() {
$datePicker.data('DateTimePicker').viewMode('years');
}, 1);
});
<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.18.1/moment.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datetimepicker/4.17.47/js/bootstrap-datetimepicker.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" />
<link href="https://cdn.rawgit.com/Eonasdan/bootstrap-datetimepicker/25c11d79/build/css/bootstrap-datetimepicker.min.css" rel="stylesheet" />
<br/>
<!--Space for the fiddle-->
<div class="container">
<div class="row">
<div class='col-sm-6'>
<div class="form-group">
<div class='input-group date' id='myDatepicker'>
<input type='text' class="form-control" />
<span class="input-group-addon">
<span class="glyphicon glyphicon-calendar"></span>
</span>
</div>
</div>
</div>
</div>
</div>
我正在使用 package. Specifically ThIS。
一切正常,我点击日期选择器,选择年份,然后选择月份,然后选择日期,然后选择器关闭。
但是当它关闭时我再次点击它,只有最后一天的日历显示,这意味着它不会从一年开始重新开始。
我要的是,年复一年,月复一日,重新开始。
这里是JsFiddle
这是我的代码:
<div class='input-group date' id='datetimepicker9'>
<input type='text' class="form-control" />
<span class="input-group-addon">
<span class="glyphicon glyphicon-calendar"></span>
</span>
</div>
Js :
$(function () {
$('#datetimepicker9').datetimepicker({
viewMode: 'years'
});
});
您可以重置 viewMode
using dp.hide
事件和 setTimeout
let $datePicker = $('#myDatepicker').datetimepicker({
useCurrent: false,
viewMode: 'years'
});
$datePicker.on('dp.hide', function(event) {
setTimeout(function() {
$datePicker.data('DateTimePicker').viewMode('years');
}, 1);
});
<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.18.1/moment.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datetimepicker/4.17.47/js/bootstrap-datetimepicker.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" />
<link href="https://cdn.rawgit.com/Eonasdan/bootstrap-datetimepicker/25c11d79/build/css/bootstrap-datetimepicker.min.css" rel="stylesheet" />
<br/>
<!--Space for the fiddle-->
<div class="container">
<div class="row">
<div class='col-sm-6'>
<div class="form-group">
<div class='input-group date' id='myDatepicker'>
<input type='text' class="form-control" />
<span class="input-group-addon">
<span class="glyphicon glyphicon-calendar"></span>
</span>
</div>
</div>
</div>
</div>
</div>