jQuery UI Datepicker getDate returns today's date on invalid date

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-11 02:04:22

问题


When using jQuery UI's date-picker, if you call getDate while the text in the text box is not a valid date, getDate returns today's date.

Example

How can I distinguish between today's date and an invalid date when retrieving the date?


回答1:


Looks like this is normal behaviour for the widget. Here's a function that includes support for invalid date checking:

/* Gets the current value
 * @return Date The result or null if no date is present
 * @throws If the entered value is invalid
 */
function getDate(datePicker) {
    datePicker = $(datePicker);

    var format = datePicker.datepicker("option", "dateFormat"),
        text = datePicker.val(),
        settings = datePicker.datepicker("option", "settings");

    return $.datepicker.parseDate(format, text, settings);
}


来源:https://stackoverflow.com/questions/26579899/jquery-ui-datepicker-getdate-returns-todays-date-on-invalid-date

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!