我需要在JQuery UI日期選擇器的某些日期顯示自定義文本,更確切地說,可以爲某些日期呈現特定的價格。 我的想法是使用beforeShowDay在這些日期的標題中附加特定的價格,然後在beforeShow中查看每個td並將標題的文本放入單元格中。例如:向jquery ui datepicker單元添加文本的方法?
var m, d, y, checkDate, specificPrice = '';
var specificPrices = {"2013-3-8":"300 EUR", "2013-2-26":"263 EUR"}
$('#my-datepicker').datepicker({
beforeShowDay: function checkAvailable(date) {
m = date.getMonth();
d = date.getDate();
y = date.getFullYear();
checkDate = y + '-' + (m+1) + '-' + d;
if(specificPrices[checkDate]){
specificPrice = specificPrices[checkDate];
}else{
specificPrice = '';
}
return [true, "", specificPrice];
},
beforeShow: function(elem, inst){
$('table.ui-datepicker-calendar tbody td', inst.dpDiv).each(function(){
var calendarPrice = $(this).attr('title');
if(calendarPrice != undefined){
$(this).find('a').append('<span class="calendar-price">' + calendarPrice + '<span>');
}
});
}
});
,這會使得在第一個日曆價格呈現(月/年改變之前)和僅在線日曆。
我需要價格顯示在非內聯日曆上以及任何月/年的變化。
我嘗試了一些其他變體,並嘗試使用onChangeMonthYear,但迄今沒有成功。
謝謝你的關注,你的想法是受歡迎的。
我已經開發了用於標準和內聯datepickers工作的解決方案,您可能會感興趣,看到我的【答案】(http://stackoverflow.com/a/22822254/2464634)以下。 – 2014-04-03 15:06:51
對不起,自從我問這個問題以來,已經有一年多的時間了。在這一刻,我已經超出了這個問題的範圍。雖然我會盡力找一些空閒時間來審查你的方法,以便接受是一種解決方案。 – yuga 2014-04-12 04:09:36