jQuery UI Datepicker getDate在无效日期返回今天的日期 [英] jQuery UI Datepicker getDate returns today's date on invalid date

查看:116
本文介绍了jQuery UI Datepicker getDate在无效日期返回今天的日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当使用jQuery UI的日期选择器时,如果您在文本框中的文本不是有效日期时调用 getDate getDate 返回今天的日期。

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.

示例

如何在检索日期时区分今天的日期和无效日期?

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

推荐答案

看起来这是小部件的正常行为。这是一个包含无效日期检查支持的函数:

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

这篇关于jQuery UI Datepicker getDate在无效日期返回今天的日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆