在何处触发“请输入有效日期".在jquery.validate.js中 [英] Where trigger the "Please enter a valid date." in jquery.validate.js
问题描述
我正在使用jQuery UI版本1.12.1和jQuery Validation v1.15.0
I am using jQuery UI version 1.12.1 and jQuery Validation v1.15.0
我创建了一个日期选择器,如下所示:
I created a datepicker as follow:
if ($.fn.datepicker) $(':input.date').datepicker({
changeMonth: true,
changeYear: true
});
默认情况下,日期格式为mm/dd/yyyy,例如2017年1月26日,代表2017年1月26日.
By default, the date format will be mm/dd/yyyy, for example 01/26/2017, represent 26th January 2017.
我正在尝试将日期格式更改为dd/mm/yyyy,所以我将日期选择器更改为:
I am trying to change the date format to be dd/mm/yyyy, so I change the datepicker as follow:
if ($.fn.datepicker) $(':input.date').datepicker({
changeMonth: true,
changeYear: true,
dateFormat: 'dd/mm/yy'
});
好吧,现在日期格式可以按我希望的那样正确显示,它变成了2017年1月26日,代表2017年1月26日.
Well, now the date format display correct as I wish, it become 26/01/2017, represent 26th January 2017.
但是,它会抛出红色错误消息Please enter a valid date.
.调试之后,我发现错误消息实际上来自第357行的jquery.validate.js:
However, it throw a red error message Please enter a valid date.
. After my debugging, I found that the error message is actually come from the jquery.validate.js at line 357:
messages: {
// some other code
date: "Please enter a valid date.",
// some other code
},
您知道为什么/为什么会抛出此错误消息吗?
Any idea how/why it throw this error message?
我的jQuery UI版本与jQuery验证版本不兼容吗?
Is it my jQuery UI version not compatible with the jQuery validation version?
请告知.
推荐答案
找到它,实际上是由jquery.validate.min.js中的日期方法验证触发的,位于第1356行:
Found it, it was actually trigger by a date method validation in jquery.validate.min.js, which is in line 1356:
// http://jqueryvalidation.org/date-method/
date: function( value, element ) {
return this.optional( element ) || !/Invalid|NaN/.test( new Date( value ).toString() );
},
这篇关于在何处触发“请输入有效日期".在jquery.validate.js中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!