你如何 console.log 使用 JS 或 jQuery 从 bootstraps datetimepicker 获取日期
How do you console.log the date from bootstraps datetimepicker with JS or jQuery
当我单击按钮时,我想 console.log
将日期和时间插入到输入中,但是当我尝试时,我只得到 'undefined'。
$('#picker-start').datetimepicker({
timepicker: true,
datepicker: true,
format: 'y-m-d H:i',
onShow: function(ct) {
this.setOptions({
maxDate: $('#picker-end').val() ? $('#picker-end').val() : false
})
}
})
$('#picker-end').datetimepicker({
timepicker: true,
datepicker: true,
format: 'y-m-d H:i',
onShow: function(ct) {
this.setOptions({
minDate: $('#picker-start').val() ? $('#picker-start').val() : false
})
}
});
<div class="form-group">
<label for="">Start Date</label>
<input type="text" id="picker-start" class="form-control">
<label for="">Due Date</label>
<input type="text" id="picker-end" class="form-control">
<button type="submit" id="btn-time">get date</button>
</div>
HTML:
<div class="form-group">
<label for="">Start Date</label>
<input type="text" id="picker-start" class="form-control">
<label for="">Due Date</label>
<input type="text" id="picker-end" class="form-control">
<button type="button" id="btn-time">get date</button>
</div>
jQuery:
$('#btn-time').on("click", function() {
var startDate = $('#picker-start').val()
var endDate = $('#picker-end').val()
console.log(startDate+' - '+endDate);
});
当我单击按钮时,我想 console.log
将日期和时间插入到输入中,但是当我尝试时,我只得到 'undefined'。
$('#picker-start').datetimepicker({
timepicker: true,
datepicker: true,
format: 'y-m-d H:i',
onShow: function(ct) {
this.setOptions({
maxDate: $('#picker-end').val() ? $('#picker-end').val() : false
})
}
})
$('#picker-end').datetimepicker({
timepicker: true,
datepicker: true,
format: 'y-m-d H:i',
onShow: function(ct) {
this.setOptions({
minDate: $('#picker-start').val() ? $('#picker-start').val() : false
})
}
});
<div class="form-group">
<label for="">Start Date</label>
<input type="text" id="picker-start" class="form-control">
<label for="">Due Date</label>
<input type="text" id="picker-end" class="form-control">
<button type="submit" id="btn-time">get date</button>
</div>
HTML:
<div class="form-group">
<label for="">Start Date</label>
<input type="text" id="picker-start" class="form-control">
<label for="">Due Date</label>
<input type="text" id="picker-end" class="form-control">
<button type="button" id="btn-time">get date</button>
</div>
jQuery:
$('#btn-time').on("click", function() {
var startDate = $('#picker-start').val()
var endDate = $('#picker-end').val()
console.log(startDate+' - '+endDate);
});