我希望使用 jquery 从 datetimepicker ( http://eonasdan.github.io/bootstrap-datetimepicker/ ) 中获取日期值,以查找 2 个输入日期之间的差异。我花了好几天的时间来做这件事,但一点运气都没有。这是我的代码:
HTML
<div class="col-sm-4">
<label for="label_duration" id="lblStartDate"
class="col-sm-2 control-label">Start Date</label>
<div class='input-group date' id='datetimepicker1'>
<input type='text' class="form-control" name="startdate"
id="startdate" placeholder="yyyy-mm-dd" required/>
<span class="input-group-addon">
<span class="glyphicon glyphicon-calendar"></span>
</span>
</div>
</div>
<div class="col-sm-4">
<label for="label_duration" id="lblEndDate" class="col-sm-2
control-label">End Date</label>
<div class='input-group date' id='datetimepicker2'>
<input type='text' class="form-control" name="enddate" id="enddate"
placeholder="yyyy-mm-dd" required/>
<span class="input-group-addon">
<span class="glyphicon glyphicon-calendar"></span>
</span>
</div>
</div>
jQuery
$(function () {
$('#datetimepicker1').datetimepicker({
viewMode: 'years',
format: 'YYYY-MM-DD'
});
$('#datetimepicker2').datetimepicker({
viewMode: 'years',
format: 'YYYY-MM-DD'
});
});