简体   繁体   English

尝试验证jQuery UI Datepicker

[英]Trying to validate jQuery UI Datepicker

I am trying to check if a date is older than today's date & show an error if true. 我正在尝试检查日期是否早于今天的日期,如果为true,则显示错误。 What is currently happening is if the month is less than today's month, the error is showing even if the year is set to 2014 or beyond. 当前正在发生的是,如果该月份小于今天的月份,则即使该年份设置为2014年或更晚,也会显示错误。 For example today is 4/18/2013 which doesn't have an error, but 4/17/2014 & 3/17/2014 get errors but 5/17/2013 does not. 例如,今天是4/18/2013,没有错误,但是4/17/2014和3/17/2014发生了错误,而5/17/2013没有。 It seems the year is being ignored during the check. 在检查期间似乎忽略了这一年。 Hope that made a little sense... 希望这有点道理...

    $("#expDate").datepicker({
        changeMonth: true,
        changeYear: true,
        minDate: 0,
        onClose: function(selectedDate) {
            var currDate = $.datepicker.formatDate('mm/dd/yy', new Date());
            if (selectedDate < currDate) {              
                $("#warning").append("The number has expired"); 
            } else {
                $("#warning").html(""); 
            }
        }
    });

您可以使用maxDate选项直接进行操作

$("#datepicker").datepicker({ maxDate: new Date() });

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM