2011-01-07 56 views
1

你好我使用jQuery UI日曆來顯示我的事件,設計是光滑的,它完美的作品。jQuery UI日曆,添加到選定日期的鏈接可能嗎?

但是,我想添加鏈接到我的活動(在我的日曆上突出顯示的日子),我找不到任何東西來幫助我編碼。

這裏是我的代碼,選擇天,我想並添加事件名稱的提示:

$("#div-calendar").datepicker({ beforeShowDay: highlightDays }); 
var dates = //Array Containing Events dates, names and link. 

//Highlight days on the calendar 
function highlightDays(date) { 
    for (var i = 0; i < dates.length; i++) { 
     if (date - dates[i][0] == 0) { return [true, '', dates[i][1]]; } 
    } 
    return [false]; 
} 

我發現的唯一的語法是:

return [true, '', dates[i][1]]; 

第一個參數是高亮顯示日期,第二個是自定義CSS,第三個是工具提示。

那麼有可能在那些日子裏添加一個鏈接嗎?非常像我使用工具提示。

謝謝。

回答

1

確定這是不好的,但我發現沒有更好的解決方案在那裏。我使用類參數傳遞值。

它顯示jQuery Date Picker日曆上的事件,它顯示每個事件的自定義工具提示,並且單擊時它會將您帶到該事件的詳細頁面。

$("#div-calendar").datepicker({ beforeShowDay: highlightDays, onSelect: SelectedDay }); 
dates = //Array Containing Events [date, name, id] of each event. (from ajax) 


//Highlight days on the calendar, the array *dates* in this example. 
function highlightDays(date) { 
    for (var i = 0; i < dates.length; i++) { 
     if (date - dates[i][0] == 0) { 
      //1st parameter is highlight the date, 2nd is custom css and 3rd is tooltip. 
      return [true, 'ID=' + dates[i][2], dates[i][1]]; 
     } 
    } 
    return [false]; 
} 


//When a highlighted day is clicked 
function SelectedDay(date, inst) { 

    //hack so the UI is updated see : http://stackoverflow.com/questions/4854635/jquery-datepicker-onselect-event-fired-to-early 
    window.setTimeout(function() { 

     //Get the clicked cell classes 
     var classes = inst.dpDiv.find('.ui-datepicker-current-day a').parent().attr("class").split(" "); 

     //loop through classes, read the ID=x class and extract 'x', then redirect to desired page 
     for (var i in classes) { 
      if (classes[i].substring(0, 3) == "ID=") { location.href = "/mypage.php?ID=" + classes[i].substring(3) } 
     } 

    }, 0); 

} 
0

On Select屬性可以使用。當有人點擊某個日期時,您可以查看該日期是否有與之相關的信息。

此外,您可以嘗試使用jQuery wrap包裝單個HTML日期元素與你的鏈​​接

+0

你能鏈接一些例子嗎?在進入這個領域之前,我希望看到有人作爲首發。 – 2011-01-10 13:38:44

相關問題