按下取消后,jquery 对话框上的 jquery datepicker 将不会显示

发布于 2024-12-27 08:17:47 字数 907 浏览 3 评论 0原文

我已经在 jquery 的对话框上成功创建了一个 jquery 日期选择器,该对话框是通过 load() 函数加载的。

我能够通过覆盖对话框的打开事件来实现它:

 open: function (event, ui) {
                    if ($('input.date-picker').length > 0) {
                        $('input.date-picker').datepicker({
                            showOn: "button",
                            buttonImage: "/Content/images/calendar.gif",
                            buttonImageOnly: true
                        });
                        $('input.date-picker').datepicker("refresh");
                    }
                },

按下图像按钮后,日期选择器成功显示。但我注意到一些奇怪的事情,当我打开对话框,单击“取消”然后再次打开对话框并单击日历图像按钮时,日期选择器不会显示。

可能有帮助,我还覆盖了对话框的关闭事件:

close: function (event, ui) {
                    $('input.date-picker').datepicker("destroy");
                    $(this).dialog("destroy");
                }

谢谢

I've successfully created a jquery datepicker on jquery's dialog box that was loaded via load() function.

I was able to achieve it by overriding dialog box's open event:

 open: function (event, ui) {
                    if ($('input.date-picker').length > 0) {
                        $('input.date-picker').datepicker({
                            showOn: "button",
                            buttonImage: "/Content/images/calendar.gif",
                            buttonImageOnly: true
                        });
                        $('input.date-picker').datepicker("refresh");
                    }
                },

The datepicker successfully show after I press the image button. But I noticed something strange, when I open the dialog, click cancel then open the dialog again and click the calendar image button, the datepicker won't show.

Might help, I've also overriden dialog's close event:

close: function (event, ui) {
                    $('input.date-picker').datepicker("destroy");
                    $(this).dialog("destroy");
                }

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

尤怨 2025-01-03 08:17:47

在 close 函数中,您尝试销毁输入上的日期选择器,其中类为 date-picker 但在上次调用 datepicker 创建之后,输入的类已更改为 hasDatepicker 所以尝试使用

$('input.hasDatepicker').datepicker("destroy");

编辑:

日期选择器应该实现此 close 方法:

close: function (event, ui) {
     $('input.hasDatepicker').datepicker("destroy");
     $(this).dialog("destroy");
     $(this).remove();
}

In the close function you try to destroy datepicker on input where class is date-picker but after previous call to datepicker creation the class of the input has changed to hasDatepicker so try to use

$('input.hasDatepicker').datepicker("destroy");

Edit :

The datepicker should implement this close method :

close: function (event, ui) {
     $('input.hasDatepicker').datepicker("destroy");
     $(this).dialog("destroy");
     $(this).remove();
}
送舟行 2025-01-03 08:17:47

对我有用的是 -

在对话框内,如果我有多个带有类 datepicker 的输入,那么

$(".datepicker").removeClass('hasDatepicker').datepicker();  

基本上,在初始化 datepicker 之前删除类 hasDatepicker > 再次。

我使用的是 jquery.ui.datepicker版本 1.8.18

What worked for me was -

Inside the dialog, if I have multiple inputs with class datepicker , then

$(".datepicker").removeClass('hasDatepicker').datepicker();  

Basically, to remove the class hasDatepicker before initializing datepicker again.

I was on version 1.8.18 of jquery.ui.datepicker

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文