jQuery's datepicker allows you to highlight dates using the BeforeShowDay callback.
Is it possible to pass a second parameter to the method?
$(selector).datepicker({beforeShowDay: selectedDay});
function selectedDay(date) {
// Do stuff
return [true, 'class_name'];
}
As you can see, the parameter date
is automatically passed to the selectedDay method, thus making me unsure as to how to pass a second parameter.
Cheers.
I was wondering about the same question and I think I found the answer:
function selectedDay(date, param ) {
// Do stuff with param
return [true, ''];
}
function doStuff(){
var param = "param_to_pass";
$(selector).datepicker({
beforeShowDay: function (date){
return selectedDay(date, param );
}
});
}
If I understand correctly, you can just create another function and pass any params you want:
function foo (param) { ... }
function selectedDay (date) {
foo(param);
return [true, 'class_name'];
}
$(selector).datepicker({beforeShowDay: selectedDay});
You can write a function which returns an array of dates
function selectedDay(date1,date2) {
// your code
return dates[];
}
and then
$(selector).datepicker({beforeShowDay: selectedDay});
just an idea, absolutely not sure if it works
I resorted to not-the-best-practice to solve my issue. I simply made the second parameter to pass a global. It'll do the job for the time being.
$(selector).datepicker({beforeShowDay: selectedDay});
var my_param = x;
function selectedDay(date) {
// Do stuff, use my_param
return [true, 'class_name'];
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.