0
我是一個在商業網站上使用jQuery UI datepicker設置發貨日期的新手。我想填充日期輸入字段與第一有效出貨日期,其定義爲:將jQuery UI日期選擇器設置爲有效的第一個日期
- 比今天更高版本;和
- 無論是週一或週二
(還有其他的條件,但我忽略了他們的時刻。)
我寫這篇文章,並在接下來的幾天中,正確的這個日期的值是2011年8月8日。
這裏是頁:
http://www.lolacookies.com/gifts/
這裏是我的代碼,這是行不通的。評論部分是應該做的工作。輸入的值根本沒有被設置;在之前的嘗試中,日期已設置爲minDate的值,但不包含任何其他值。
$(document).ready(function(){
$(".datepicker").datepicker({
beforeShowDay: nonWorkingDates,
hideIfNoPrevNext: true,
numberOfMonths: 1,
minDate: "+1d",
maxDate: "+3M",
showAnim: "blind",
showOn: "both",
buttonImage: "/images/misc/calendar.png",
buttonImageOnly: true,
buttonText: "Select a date"
});
//set firstShippingDate to value of minDate
//we don't ship on same day, so minDate is today + 1d
var firstShippingDate = $(".datepicker").datepicker("option", "minDate");
//we ship only on Monday and Tuesday, so test for that
var dayOfWeek = firstShippingDate.getDay();
//if it's not Monday or Tuesday, advance firstShippingDate by one day and test again
while (dayOfWeek == 0 || dayOfWeek == 3 || dayOfWeek == 4 || dayOfWeek == 5 || dayOfWeek == 6)
{
firstShippingDate.setTime(firstShippingDate.getTime() + 86400000);
dayOfWeek = firstShippingDate.getDay();
};
//should exit loop with firstShippingDate set to first Monday or Tuesday that's not today
//set datepicker to that firstShippingDate
$(".datepicker").datepicker("setDate" , firstShippingDate);
function nonWorkingDates(date){
var day = date.getDay(), Sunday = 0, Monday = 1, Tuesday = 2, Wednesday = 3, Thursday = 4, Friday = 5, Saturday = 6;
var closedDates = [[06, 27, 2011], [06, 28, 2011], [06, 29, 2011], [07, 04, 2011]];
var closedDays = [[Sunday], [Wednesday], [Thursday], [Friday], [Saturday]];
for (var i = 0; i < closedDays.length; i++) {
if (day == closedDays[i][0]) {
return [false];
}
}
for (i = 0; i < closedDates.length; i++) {
if (date.getMonth() == closedDates[i][0] - 1 &&
date.getDate() == closedDates[i][1] &&
date.getFullYear() == closedDates[i][2]) {
return [false];
}
}
return [true];
}
});
俏皮 - 我可以想到一個萬億的用途。謝謝! – Laurence