beforeShow 事件未在 jQueryUI Datepicker 上触发 [英] beforeShow event not firing on jQueryUI Datepicker

查看:24
本文介绍了beforeShow 事件未在 jQueryUI Datepicker 上触发的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

无论我尝试什么,我都无法在我的日期选择器上触发 beforeShow 事件.这是我的代码:

No matter what I try, I'm not able to get the beforeShow event to fire on my datepicker. Here's my code:

$('#calendar').datepicker({
inline: true,
dateFormat: 'mm,dd,yy',
beforeShow: function(input, inst) { alert('before'); }
});

我已将 beforeShowDay 和 onSelect 事件添加到我的日期选择器,并且它们确实正确触发.有没有其他人遇到过这个问题?

I've added beforeShowDay and onSelect events to my datepicker, and they do fire correctly. Has anyone else had trouble with this?

推荐答案

这是我的团队提出的解决方案,这样我们就不必记住每次更新时都修改 jQuery 文件.只需将此添加到您自己的脚本中并包含它:

Here's the solution my team came up with so we don't have to remember to modify the jQuery files every time there's an update. Just add this to your own script and include it:

(function ($) {
    $.extend($.datepicker, {

        // Reference the orignal function so we can override it and call it later
        _inlineDatepicker2: $.datepicker._inlineDatepicker,

        // Override the _inlineDatepicker method
        _inlineDatepicker: function (target, inst) {

            // Call the original
            this._inlineDatepicker2(target, inst);

            var beforeShow = $.datepicker._get(inst, 'beforeShow');

            if (beforeShow) {
                beforeShow.apply(target, [target, inst]);
            }
        }
    });
}(jQuery));

这篇关于beforeShow 事件未在 jQueryUI Datepicker 上触发的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆