也許我
$(function() {
$('#datetimepicker').datetimepicker();
$('#datetimepicker').on("change.datetimepicker", function (e) {
console.log(e.date);
});
});
你可以使用這個太獲取日期錯誤,但我解釋的方式「注意:所有選項都通過數據屬性」訪問它說,訪問功能在格式如下
$("#YOU_SELECTOR").data('DateTimePicker').FUNCTION();
如果您嘗試console.log($("#YOU_SELECTOR").data('DateTimePicker'));
你會看到,它通過data
屬性打印所有這些,它說are accessible
功能,有幾個我打印下面
{
"destroy": function() {
H(), I(), i.widget.remove(), i.element.removeData("DateTimePicker"), i.component && i.component.removeData("DateTimePicker")
},
"show": function (a) {
if (!l().prop("disabled")) {
if (i.options.useCurrent && "" === l().val()) {
if (1 !== i.options.minuteStepping) {
var c = b(),
d = i.options.minuteStepping;
c.minutes(Math.round(c.minutes()/d) * d % 60).seconds(0), i.setValue(c.format(i.format))
} else i.setValue(b().format(i.format));
o("", a.type)
}
a && "click" === a.type && i.isInput && i.widget.hasClass("picker-open") || (i.widget.hasClass("picker-open") ? (i.widget.hide(), i.widget.removeClass("picker-open")) : (i.widget.show(), i.widget.addClass("picker-open")), i.height = i.component ? i.component.outerHeight() : i.element.outerHeight(), n(), i.element.trigger({
type: "dp.show",
date: b(i.date)
}), G(), a && B(a))
}
},
"disable": function() {
var a = l();
a.prop("disabled") || (a.prop("disabled", !0), H())
},
"enable": function() {
var a = l();
a.prop("disabled") && (a.prop("disabled", !1), F())
},
"hide": function() {
var a, c, d = i.widget.find(".collapse");
for (a = 0; a < d.length; a++)
if (c = d.eq(a).data("collapse"), c && c.transitioning) return;
i.widget.hide(), i.widget.removeClass("picker-open"), i.viewMode = i.startViewMode, E(), i.element.trigger({
type: "dp.hide",
date: b(i.date)
}), I()
},
"setValue": function (a) {
b.locale(i.options.language), a ? i.unset = !1 : (i.unset = !0, K()), a = b.isMoment(a) ? a.locale(i.options.language) : a instanceof Date ? b(a) : b(a, i.format, i.options.useStrict), a.isValid() ? (i.date = a, K(), i.viewDate = b({
y: i.date.year(),
M: i.date.month()
}), t(), x()) : p(a)
},
"getDate": function() {
return i.unset ? null : b(i.date)
},
"setDate": function (a) {
var c = b(i.date);
i.setValue(a ? a : null), o(c, "function")
},
"setDisabledDates": function (a) {
i.options.disabledDates = O(a), i.viewDate && q()
},
"setEnabledDates": function (a) {
i.options.enabledDates = O(a), i.viewDate && q()
},
"setMaxDate": function (a) {
void 0 !== a && (i.options.maxDate = b.isMoment(a) || a instanceof Date ? b(a) : b(a, i.format, i.options.useStrict), i.viewDate && q())
},
"setMinDate": function (a) {
void 0 !== a && (i.options.minDate = b.isMoment(a) || a instanceof Date ? b(a) : b(a, i.format, i.options.useStrict), i.viewDate && q())
}
.............. and more,
通過點擊一個鏈接,在演示中看到下面的調用getDate()
。您可以在更改日期後檢查以確認。
$(document).ready(function() {
var picker = $('#datetimepicker7').datetimepicker();
//console.log(picker.datetimepicker('data-view-date'));
//console.log($('#datetimepicker7').datetimepicker('data-show'));
$("#tog").on('click', function() {
//console.log($('#datetimepicker7').data('DateTimePicker'));
console.log($('#datetimepicker7').data('DateTimePicker').getDate());
})
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.19.2/moment.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/js/bootstrap.min.js"></script>
<link href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/css/bootstrap.css" rel="stylesheet" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datetimepicker/3.1.4/js/bootstrap-datetimepicker.min.js"></script>
<link href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datetimepicker/3.1.4/css/bootstrap-datetimepicker.css" rel="stylesheet" />
<div class="container">
<div class='col-md-5'>
<div class="form-group">
<div class="input-group date" id="datetimepicker7" data-target-input="nearest">
<input type="text" class="form-control datetimepicker-input" data-target="#datetimepicker7" />
<span class="input-group-addon" data-target="#datetimepicker7" data-toggle="datetimepicker">
<span class="glyphicon glyphicon-calendar"></span>
</span>
</div>
</div>
</div>
<a href="#." id="tog">toggle</a>
</div>
我認爲你可以在HTML輸入存取權限,所以我不知道你想的那一刻元素來使用,那麼你可以使用IO變化事件則可以達到通過PARAMS e.date的時刻克隆元素 –
我會認爲有一個簡單的方法應該是一個「時刻」對象,這是我正在尋找的日期對象。 – Jaylen
'$('#datetimepicker')。datetimepicker('date')'適合我,你能提供一個片段或小提琴來展示這個問題嗎? – VincenzoC