0
我知道還有其他類似我的問題,但無論我做什麼,都會返回null
或undefined
。我不知道我要去哪裏錯。獲取Bootstrap DateTimePicker的價值
HTML
<div class="col-sm-6" style="height:130px;">
<div class="form-group">
<div class='input-group date' id='datetimepicker10'>
<input type='text'></input>
<span class="input-group-addon">
<span class="glyphicon glyphicon-calendar"></span>
</span>
</div>
</div>
</div>
<div>
<input type="submit" value="Check" onclick="dateCheck()" />
</div>
的JavaScript
var dates = {};
$(function() {
$('#datetimepicker10').datetimepicker({
viewMode: 'years',
format: 'YYYY-MM-DD'
});
//dates.strt = $('#datetimepicker10').datetimepicker().getDate(); //returns UNDEFINED
//dates.strt = $('#datetimepicker10').find('input').val(); // doesn't display anything
dates.diffInDays = (new Date($('#datetimepicker10').val()).valueOf()-new Date('2017-04-26').valueOf())/(3600*24*1000);
dates.str = $('#datetimepicker10').data("DateTimePicker").date();
});
function dateCheck() {
alert(dates.str);
};
所以代碼沒有工作,因爲它在document.ready內?它終於奏效了,謝謝! – jc13