我需要在Jquery UI datepicker的某些日期显示自定义文本,更准确地说,为某些日期呈现特定价格.我的想法是使用beforeShowDay在这些日期的标题中附加特定价格,然后在beforeShow中检查每个td并将标题的文本放入单元格.例:
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>');
} …Run Code Online (Sandbox Code Playgroud)