问题
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