本文介绍了检查日期是否在过去Javascript的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
所有,
我正在使用jQuery UI作为日期选择器。我试图用javascript检查,但用户输入的日期是过去的。这是我的表单代码:
All,I'm using the jQuery UI for the date picker. I'm trying to check with javascript though that the date the user has entered is in the past. Here is my form code:
<input type="text" id="datepicker" name="event_date" class="datepicker">
然后,如何使用Javascript检查这个,以确保它不是过去的日期?谢谢
Then how would I check this with Javascript to make sure it isn't a date in the past? Thanks
推荐答案
var selectedDate = $('#datepicker').datepicker('getDate');
var now = new Date();
now.setHours(0,0,0,0);
if (selectedDate < now) {
// selected date is in the past
}
这篇关于检查日期是否在过去Javascript的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!