2011-09-26 73 views
0
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事件来标识所选日期,并将该值存储在全局声明的变量中。使用变量我已设置minDate$("#MaritalStatusDate")。但日期并没有根据minDate价值被禁用。在为变量赋值时是否需要更改日期格式?任何人都可以帮助我这样做吗?动态禁用日期在jQuery日期选择器

回答

1

您可以简单地设置minDate$('#MaritalStatusDate')onSelect事件。

$("#BirthDate").datepicker({ 
    ... 
    onSelect: function(dateText, inst) { 
     $('#MaritalStatusDate').datepicker('option', 'minDate', dateText); 
    } 
}); 

看到这个在行动:http://jsfiddle.net/william/2q7TN/

+0

嗨威廉。我使用了你的脚本,但当点击提交按钮并返回到视图时,日期选择器不显示。 –

+0

@kavithaReddy,我不确定你的意思。你能通过jsfiddle来说明吗? –

相关问题