我正在尝试实现Bootstrap Datetime选择器;以下是链接;
https://fiddle.jshell.net/0sowpm1v/2/
问题1: 目前,即使用户没有选择时间组件,选择器也将时间显示为00:00。 我想要实现的是,如果用户没有选择任何时间,那么时间段将会下降。
如果用户选择日期为“2015-05-01”,则输出应为“2015-05-01”而不是“2015-05-01 00:00”。
问题2:
如果这不可能我们可以在选择器的'onClose'事件中触发任何函数调用吗?
N.B:有关的日期时间选择器不支持'onClose'事件,我不知道它的等效方法。
以下是我的代码:
<div class="container">
<div class="row">
<div class='col-sm-3'>
<div class="form-group">
<div class='input-group date' id='datetimepicker1'>
<input type='text' class="form-control" />
<span class="input-group-addon">
<span class="glyphicon glyphicon-calendar"></span>
</span>
</div>
</div>
</div>
这是DateTime选择器的JQuery绑定;
$('#datetimepicker1').datetimepicker({
format : "YYYY-MM-DD HH:mm"
});
答案 0 :(得分:0)
您可以使用此代码段
$('#datetimepicker1').datetimepicker({
format : "YYYY-MM-DD",
autoclose: true,
});
答案 1 :(得分:-1)
这只是一个解决方法。如果有人有更好的答案,欢迎您分享。
这是我实施的JQuery解决方法。
$('#datetimepicker1').datetimepicker({
format: "YYYY-MM-DD HH:mm",
useStrict: true,
keepInvalid: true
});
$("#datetimepicker1").on("dp.change", function(e) {
if ($('#lblValue').text() == 1) {
$('#lblValue').text('2');
$('#txtDate').val('');
} else if ($('#lblValue').text() == 2) {
$('#lblValue').text('3');
}
});
$("#datetimepicker1").on("dp.hide", function(e) {
if ($('#lblValue').text() == 2 && $('#txtDate').val() == '') {
$('#lblValue').text('4');
} else {
$('#lblValue').text('2');
}
if ($("#txtDate").val() != "" && $("#txtDate").val().trim().substring(16, 10).trim() == "00:00") {
$("#txtDate").val($("#txtDate").val().trim().substring(10, 0));
}
});