如何停止 datetimepicker 默认情况下在文本框中设置今天的日期 onclick
How to stop datetimepicker setting todays date in textbox by default onclick
当我们select 日历图标时,它会自动将今天的日期设置为文本框。
datetimepicker() 函数中是否有任何 parameter/option 可以设置为 false 或 null 以防止 datetimepicker() 默认将今天的日期设置为文本框。
如果某人没有 select 日历中的任何日期,则文本框应该为空,而不是由 datetimepicker() 设置今天的日期。
值得阅读文档。初始化日期时间选择器时更改 useCurrent
属性。
https://eonasdan.github.io/bootstrap-datetimepicker/Options/#usecurrent
如果您将 .datetimepicker() 用于 Bootstrap 4 + jQuery
当您单击该元素时,可能会发生日期更新的这种不良影响。
这是一种技巧,可以避免点击时用当前日期覆盖当前值,并允许正常选择选择器。
对于 Tempus Dominus 版本:
https://tempusdominus.github.io/bootstrap-4/
JS
var dateNow = new Date();
$('.datetimepicker').each(function() {
var _el = this;
$(this).datetimepicker({
autoclose: true,
allowInputToogle: true,
format: 'YYYY-MM-DD HH:mm',
defaultDate: dateNow,
});
// 'this.parent()' is the container and data-target | '_el' is the input
$(this).parent().on('change.datetimepicker', function(e) {
// HACK
if (!e.oldDate) return;
$(_el).val(e.date.format('YYYY-MM-DD HH:mm'));
});
});
HTML
<div class="form-group">
<label class="control-label"><i class="icon-right-open-outline"></i> Date</label>
<div class="input-group" id="form_datetimepicker_1">
<input name="date_selected"
id="date_selected"
class="form-control datetimepicker"
type="text"
data-toggle="datetimepicker"
value="2019-11-22 22:55:00"
data-target="#form_datetimepicker_1">
<div class="input-group-append" data-target="#form_datetimepicker_1" data-toggle="datetimepicker">
<div class="input-group-text"><i class="fa fa-calendar"></i></div>
</div>
</div>
</div>
当我们select 日历图标时,它会自动将今天的日期设置为文本框。 datetimepicker() 函数中是否有任何 parameter/option 可以设置为 false 或 null 以防止 datetimepicker() 默认将今天的日期设置为文本框。 如果某人没有 select 日历中的任何日期,则文本框应该为空,而不是由 datetimepicker() 设置今天的日期。
值得阅读文档。初始化日期时间选择器时更改 useCurrent
属性。
https://eonasdan.github.io/bootstrap-datetimepicker/Options/#usecurrent
如果您将 .datetimepicker() 用于 Bootstrap 4 + jQuery
当您单击该元素时,可能会发生日期更新的这种不良影响。
这是一种技巧,可以避免点击时用当前日期覆盖当前值,并允许正常选择选择器。
对于 Tempus Dominus 版本: https://tempusdominus.github.io/bootstrap-4/
JS
var dateNow = new Date();
$('.datetimepicker').each(function() {
var _el = this;
$(this).datetimepicker({
autoclose: true,
allowInputToogle: true,
format: 'YYYY-MM-DD HH:mm',
defaultDate: dateNow,
});
// 'this.parent()' is the container and data-target | '_el' is the input
$(this).parent().on('change.datetimepicker', function(e) {
// HACK
if (!e.oldDate) return;
$(_el).val(e.date.format('YYYY-MM-DD HH:mm'));
});
});
HTML
<div class="form-group">
<label class="control-label"><i class="icon-right-open-outline"></i> Date</label>
<div class="input-group" id="form_datetimepicker_1">
<input name="date_selected"
id="date_selected"
class="form-control datetimepicker"
type="text"
data-toggle="datetimepicker"
value="2019-11-22 22:55:00"
data-target="#form_datetimepicker_1">
<div class="input-group-append" data-target="#form_datetimepicker_1" data-toggle="datetimepicker">
<div class="input-group-text"><i class="fa fa-calendar"></i></div>
</div>
</div>
</div>