当我单击按钮时,我想要console.log在输入中插入的日期和时间,但是当我尝试时,我只得到“未定义”。
$('#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);
});