JQuery Datepicker BeforeShowDay Second Parameter

jQuery datepicker allows you to highlight dates using the BeforeShowDay callback.

Is it possible to pass the second parameter to a method?

$(selector).datepicker({beforeShowDay: selectedDay});   

function selectedDay(date) {

    // Do stuff

    return [true, 'class_name'];
}

As you can see, the parameter is dateautomatically passed to the selectedDay method, so I'm not sure how to pass the second parameter.

Greetings.

+5
source share
4 answers

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 );
        }
    }); 
}  
+16
source

If I understand correctly, you can just create another function and pass in any parameters you want:

function foo (param) { ... }
function selectedDay (date) {
  foo(param);
  return [true, 'class_name'];
}

$(selector).datepicker({beforeShowDay: selectedDay});   
0
source

,

function selectedDay(date1,date2) {
// your code
return dates[];
}

$(selector).datepicker({beforeShowDay: selectedDay});  

, ,

0

- . , . .

$(selector).datepicker({beforeShowDay: selectedDay});   

var my_param = x;
function selectedDay(date) {

    // Do stuff, use my_param

    return [true, 'class_name'];
}
0

All Articles