選擇日期時,我需要(添加課程)突出顯示幾個額外的日期。我可以利用變化:
$(".some-booking-form").on("change", function() {
var selectedDate = $(this).datepicker("getDate");
// need to highlight more dates
});
我環顧四周,但只找到了beforeShowDay在初始化時需要使用 as config 選項的解決方案。但我不能這樣做,因為它來自我正在使用的這個 CMS 中的一個插件。
uj5u.com熱心網友回復:
這是我能想出的最干凈的方法:
// setTimeout so that my fn will run at the very end
// after the datepicker init took place
setTimeout(function() {
let selectedDate;
const $datepicker = $(".yith-wcbk-booking-start-date");
// get beforeShowDay callback function on old instance of datepicker
// sot that we can call it in our own method
const oldBeforeShowDay = $datepicker.datepicker("option", "beforeShowDay");
$datepicker.datepicker("option", "beforeShowDay",
function(date) {
var result = oldBeforeShowDay.apply(this, [date]);
var _classes = result[1];
// your logic to add more highlighting classes goes here.
// _classes = ' bg-green-highlighted';
return [result[0], _classes.trim()];
});
$datepicker.change(function() {
selectedDate = $(this).datepicker("getDate");
// your logic goes here
// at this point jquery ui will hide the calendar
// $(this).datepicker("refresh"); if calendar stays open
});
}, 0);
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/447975.html
上一篇:按類或ID拖放div元素
