[英]How to validate jQuery UI Date Picker “From Date” to “To Date”
I have 2 fields "From date" and "To date". 我有2个字段“起始日期”和“截止日期”。 I am new in jQuery and I am learning it. 我是jQuery的新手,正在学习中。
I am currently using this code: 我目前正在使用此代码:
$( function() {
var dateFormat = "dd-mm-yy",
from = $( "#from" )
.datepicker({
defaultDate: "+1w",
changeMonth: true,
numberOfMonths: 3
})
.on( "change", function() {
to.datepicker( "option", "minDate", getDate( this ) );
}),
to = $( "#to" ).datepicker({
defaultDate: "+1w",
changeMonth: true,
numberOfMonths: 3
})
.on( "change", function() {
from.datepicker( "option", "maxDate", getDate( this ) );
});
function getDate( element ) {
var date;
try {
date = $.datepicker.parseDate( dateFormat, element.value );
} catch( error ) {
date = null;
}
return date;
}
});
Note: Date format should be " dd-mm-yy " 注意:日期格式应为“ dd-mm-yy ”
To grey out dates before current date, simply set minDate to current date in the datepicker configuration. 要使当前日期之前的日期灰显,只需在datepicker配置中将minDate设置为当前日期即可。
minDate: new Date()
You also should explicitly set the dateFormat option to be the same as the one you are using in $.datepicker.parseDate call. 您还应该显式地将dateFormat选项设置为与$ .datepicker.parseDate调用中使用的选项相同。
If I understood your problem correctly, this fiddle should be about right (modified your code a bit) 如果我正确理解了您的问题,那么这种提琴应该是正确的(稍微修改了您的代码)
http://jsfiddle.net/8w8v9/1846/ http://jsfiddle.net/8w8v9/1846/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.