2016-07-27 79 views
0

我想在FullCalendar月視圖中向這些單位數天添加前導零。完整日曆 - 如何在完整日曆的月份視圖中爲日期添加前導零

enter image description here

我要的是:

enter image description here

手段,如3 03 4 04年等..

+1

如果您對@ADyson解決方案不滿意,您仍然可以更改源代碼。這裏是地方https://github.com/fullcalendar/fullcalendar/blob/7ec00e827efebfe8eaa6ed324318ddd7d8870726/src/common/DayGrid.js#L150只需將「date.date()」替換爲「date.format('DD')」 –

回答

1

似乎沒有成爲一個選項爲此在fullCalendar選項curently。在不修改fullCalendar源代碼的情況下,我能想到的最好的就是這個。如果您查看呈現的日曆HTML,則會看到每天的數字都包含在<td>的CSS類fc-day-number中。所以我們可以修改<td>的內容。將此代碼直接放在日曆初始化代碼後面:

$('.fc-day-number').each(function() { 
    var day = $(this).html(); //get the contents of the td 
    //for any fields where the content is one character long, add a leading zero 
    if (day.length == 1) 
    { 
    $(this).html("0" + day); 
    } 
});  
+0

哇!它只是工作..謝謝你:) –