2011-09-26 105 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來說明嗎? –

相關問題