最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - jQuery Datepicker BeforeShowDay Second Parameter - Stack Overflow

programmeradmin2浏览0评论

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.

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.

Share Improve this question asked Jul 26, 2012 at 0:26 JarrodJarrod 9,4655 gold badges60 silver badges73 bronze badges
Add a comment  | 

4 Answers 4

Reset to default 17
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'];
}
发布评论

评论列表(0)

  1. 暂无评论