Jquery datepicker beforeShow 似乎没有传递实例

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/12953878/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-26 12:09:21  来源:igfitidea点击:

Jquery datepicker beforeShow doesn't seem to be passing the instance

jqueryjquery-uidatepicker

提问by NibblyPig

This is the JS Fiddle:

这是JS小提琴:

http://jsfiddle.net/UEnqL/

http://jsfiddle.net/UEnqL/

$("#datepicker").datepicker({ dateFormat: 'dd/mm/yy', beforeShowDay: myFunction});

function myFunction(input, inst)
{
    alert(inst);
}

According to the documentation: http://docs.jquery.com/UI/API/1.8/Datepicker#event-beforeShow

根据文档:http: //docs.jquery.com/UI/API/1.8/Datepicker#event-beforeShow

the beforeshowDaymethod accepts input and inst. inst always seems to be undefined though. This is causing me some grief as I need to get hold of the datepicker itself.

beforeshowDay方法接受 input 和 inst。inst 似乎总是未定义。这让我有些难过,因为我需要掌握日期选择器本身。

Is there a workaround?

有解决方法吗?

回答by techfoobar

The beforeshowDaycallback has only one argument; a dateobject as per documentation. the beforeShowcallback however has 2 arguments as you've mentioned.

beforeshowDay回调只有一个参数; date根据文档的对象。beforeShow但是,正如您所提到的,回调有 2 个参数。

beforeShowDay- http://docs.jquery.com/UI/API/1.8/Datepicker#event-beforeShowDay

beforeShowDay- http://docs.jquery.com/UI/API/1.8/Datepicker#event-beforeShowDay

Check this demo: http://jsfiddle.net/UEnqL/6/

检查这个演示http: //jsfiddle.net/UEnqL/6/

As you can see, the beforeShowcallback correctly passes in the element and the instance. The beforeshowDaypasses in just a date object.

如您所见,beforeShow回调正确地传入了元素和实例。将beforeshowDay在短短的日期对象通过。

回答by bipen

I think you are talking about beforeShow, not beforeShowday. Hereis the fiddle.

我想你是在说beforeShow,不是beforeShowday是小提琴。