简体   繁体   中英

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. 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. 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. 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() });

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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