我遇到了beforeShowDay
問題。jQuery Datepicker beforeShowDay僅在第一次點擊後纔有效
當我的頁面加載時,我告訴突出顯示的日子直到我點擊日曆中的某一天才突出顯示。另外,如果我點擊下一個月按鈕並返回到原始月份,則「預定」日期將按預期突出顯示。
所以,只有在日曆的最初繪製日期做日期不突出,因爲我已經編程他們做。日曆中的任何點擊都會修復其自身。
我是否缺少init選項?請參閱下面的代碼示例。我的測試網址在用戶/測試/測試通過的受保護目錄中。看看右下角的迷你卡。切換到下個月,然後返回以查看我的問題。請注意突出顯示的日子即將到來另外,請注意,點擊發生之前,「年份」下拉菜單也會丟失。
http://www.urbanbands.com/dev/cgi-bin/links/eventmgr.cgi?do=list
代碼:
<script>
$(document).ready(function(){
// get the current date
var today = new Date();
var m = today.getMonth(), d = today.getDate(), y = today.getFullYear();
// Need list of event dates for THIS month only from database.
// Declare 'dates' var before adding "beforeShowDay" option to the datepicker,
// otherwise, highlightDays() does not have the 'dates' array.
dates = [];
fetchEventDays(y, m+1);
$('#datepicker').datepicker({
dateFormat: 'yy-mm-dd',
changeMonth: true,
changeYear: true,
setDate: today,
inline: false
});
$('#datepicker').datepicker('option', 'onChangeMonthYear', fetchEventDays);
$('#datepicker').datepicker('option', 'beforeShowDay', highlightDays);
$('#datepicker').datepicker('option', 'onSelect', getday);
// ------------------------------------------------------------------
// getday
// ------------------------------------------------------------------
function getday(dateText, inst) {
$('#content').load('http://www.mydomain/eventmgr.cgi?do=view_day;date='+dateText+' #eventMgr_content', function() {
alert('Load was performed. '+dateText);
});
}
// ------------------------------------------------------------------
// fetchEventDays
// ------------------------------------------------------------------
function fetchEventDays(year, month) {
var paramStr ='?do=get_event_dates&yr=' + year + '&mo=' + month;
$.get('<%config.db_cgi_url%>/eventmgr-ajax.cgi'+ paramStr, function(data) {
var recur_dates = data.split(',');
for(var i = 0; i < recur_dates.length; i++) {
var date_parts = recur_dates[i].split('-');
dates.push(new Date(date_parts[0], date_parts[1]-1, date_parts[2]));
}
// This causes dates with events to highlight on initial draw, but
// when clicking to the next month, it switches back to orig month.
// $('#datepicker').datepicker('option', {}); // Refresh
});
}
// ------------------------------------------------------------------
// highlightDays
// ------------------------------------------------------------------
function highlightDays(date) {
for (var i = 0; i < dates.length; i++) {
if ((dates[i].getTime() == date.getTime())) {
return [true, 'highlight'];
}
}
return [true, ''];
}
});
</script>