這裏有一個快速的解決方案,應該讓你開始,反正:
var selectedDay = new Date().getDate();
$(function() {
$("#calendar").datepicker({
onSelect: function(dateText, inst) {
// Save the selected day on select (if you show other months dates, you should save the selected month also.)
selectedDay = inst.selectedDay;
},
// This is run for every day visible in the datepicker.
beforeShowDay: function (date) {
if (date.getDate() == selectedDay) {
return [true, "selected", ""]; // Here you set your css class
} else {
return [true, ""]
}
}
});
});
的beforeShowDay
功能將採取設置的CSS類的保健和其他天將其刪除。
當然,您可以擴展此選項以使用多個選定的日期,這只是爲了顯示您可以開始的位置。
你真的需要設置類*選擇*?相反,您可以在類* ui-datepicker-current-day *上繼承並設置您的樣式。 –
試試這個$('#calendar')。children('td')。addClass('selected'); –
@anujarora這會將該類添加到*所有*''元素(如果它工作的),我猜測OP只希望它在選定的日期。 –