动态禁用jQuery Datepicker中的日期 [英] Disable dates in a jquery datepicker dynamically
本文介绍了动态禁用jQuery Datepicker中的日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
var birthDate;
$(function() {
var currentDate = new Date();
$("#BirthDate").datepicker({
dateFormat: "mm/dd/yy",
showOn: "button",
buttonImage: "../Images/cal.gif",
buttonImageOnly: true,
changeMonth: true,
changeYear: true,
maxDate: currentDate,
yearRange: "-90:+10",
onSelect: function(dateText, inst) { birthDate = dateText;}
});
});
$(function() {
var currentDate = new Date();
$("#MaritalStatusDate").datepicker({
dateFormat: "mm/dd/yy",
showOn: "button",
buttonImage: "../Images/cal.gif",
buttonImageOnly: true,
changeMonth: true,
changeYear: true,
minDate: birthDate,
maxDate: currentDate,
yearRange: "-90:+10"
});
});
在上面的代码中,我尝试根据$("#BirthDate")
中选择的日期禁用$("#MaritalStatusDate")
日期。我使用BirthDate
中的onSelect
事件来标识选定的日期,并将该值存储在全局声明的变量中。我使用变量设置了$("#MaritalStatusDate")
中的minDate
。但不会根据minDate
值禁用日期。为变量赋值时是否需要更改日期格式?有谁能帮我做这件事吗?
推荐答案
只需设置minDate
for$('#MaritalStatusDate')
inonSelect
事件。
$("#BirthDate").datepicker({
...
onSelect: function(dateText, inst) {
$('#MaritalStatusDate').datepicker('option', 'minDate', dateText);
}
});
查看实际操作:http://jsfiddle.net/william/2q7TN/。
这篇关于动态禁用jQuery Datepicker中的日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文