簡體   English   中英

嘗試驗證jQuery UI Datepicker

[英]Trying to validate jQuery UI Datepicker

我正在嘗試檢查日期是否早於今天的日期,如果為true,則顯示錯誤。 當前正在發生的是,如果該月份小於今天的月份,則即使該年份設置為2014年或更晚,也會顯示錯誤。 例如,今天是4/18/2013,沒有錯誤,但是4/17/2014和3/17/2014發生了錯誤,而5/17/2013沒有。 在檢查期間似乎忽略了這一年。 希望這有點道理...

    $("#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