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
Jquery datepicker beforeShow doesn't seem to be passing the instance
提问by NibblyPig
This is the JS Fiddle:
这是JS小提琴:
$("#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 beforeshowDay
method 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 beforeshowDay
callback has only one argument; a date
object as per documentation. the beforeShow
callback 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 beforeShow
callback correctly passes in the element and the instance. The beforeshowDay
passes in just a date object.
如您所见,beforeShow
回调正确地传入了元素和实例。将beforeshowDay
在短短的日期对象通过。