我有一個jQuery UI用戶界面日期選擇器,突出顯示了我選擇日期的那一週。但是因爲我正在更改URL位置(以適應參數到最後)頁面刷新,並且我點擊並突出顯示的任何內容都會丟失。我希望能夠點擊某個日期,以及當該頁面刷新時該頁面突出顯示。需要突出顯示的那一週可以從網址中獲取,因此只需在刷新後突出顯示並突出顯示我需要幫助。刷新後日期選擇器亮點
繼承人的代碼:
$(function()
{
var startDate;
var endDate;
var selectCurrentWeek = function()
{
window.setTimeout(function() { $('.week-picker').find('.ui-datepicker-current-day a').addClass('ui-state-active')}, 1);
}
function check(d) {
if(d.length() == 2) {
dd = d;
return dd;
} else {
dd = "0" + myDateParts[0];
return dd;
}
}
var selectedWeek;//remember which week the user selected here
$('.week-picker').datepicker({
beforeShowDay: $.datepicker.noWeekends,
showOtherMonths: true,
selectOtherMonths: true,
onSelect: function(dateText, inst) {
var date = $(this).datepicker('getDate');
startDate = new Date(date.getFullYear(), date.getMonth(), date.getDate() - date.getDay() + 1);
endDate = new Date(date.getFullYear(), date.getMonth(), date.getDate() - date.getDay() + 6);
var dateFormat = 'yy-mm-dd'
var newDate = $('#startDate').text($.datepicker.formatDate(dateFormat, startDate, inst.settings));
var oldDate = document.getElementById('startDate');
var date_textnode = oldDate.firstChild;
var date_text = date_textnode.data;
myDateParts = date_text.split("-");
var dd = myDateParts[2];
var mm = myDateParts[1];
var yy = myDateParts[0];
selectCurrentWeek();
window.location.href = "/timesheet?week_commencing=" + yy + "-" + mm + "-" + dd;
},
beforeShowDay: function(date) {
var cssClass = '';
if(date >= startDate && date <= endDate)
cssClass = 'ui-datepicker-current-day';
return [true, cssClass];
},
onChangeMonthYear: function(year, month, inst) {
selectCurrentWeek();
}
});
$('.week-picker .ui-datepicker-calendar tr').live('mousemove', function() { $(this).find('td a').addClass('ui-state-hover'); });
$('.week-picker .ui-datepicker-calendar tr').live('mouseleave', function() { $(this).find('td a').removeClass('ui-state-hover'); });
});
在此先感謝
不知何故,我認爲你已經問了一個不同的ID相同的問題:http://stackoverflow.com/questions/7269582/how-to-get-datepicker-to-be-highlighted-upon-refresh/7271532 –
但我需要它來刷新,這個問題不......這也不是我的問題。 – SD1990
如果您仔細閱讀標題:「如何讓** datepicker突出顯示**刷新**」,是的,它_does_!如果您對代碼進行「區分」,我相信您的輸出不會太多,即它們幾乎完全相同。 –