jQuery UI DatePicker 在对话框窗口打开时打开

发布于 2024-12-09 03:06:21 字数 314 浏览 0 评论 0原文

我正在显示一个 jQuery UI 对话框窗口,其中包含一个 jQuery UI 日期选择器控件。问题是对话框窗口上的第一个表单字段是日期选择器,因此当窗口打开时它会接收焦点,从而导致日期选择器窗口自动打开。我不希望这种情况发生。

我尝试调用

$('#Date').datepicker('hide')

对话框窗口的 then open 函数,并且在使对话框打开的代码之后调用,但它不起作用,因为到达该代码时,日期选择器窗口尚未打开。

如何才能使日期选择器窗口在对话框窗口显示时不打开,但在用户单击输入时仍然打开?

I am displaying a jQuery UI dialog window that contains a jQuery UI datepicker control in it. The problem is that the first form field on the dialog window is the datepicker and thus it receives focus when the window opens up which in turn causes the datepicker window to automatically open. I don't want this to occur.

I have tried calling

$('#Date').datepicker('hide')

in then open function of the dialog window and also after the code that makes the dialog open but it doesn't work as when that code is reached, the datepicker window isn't open yet.

How can I make it so that the datepicker window doesn't open when the dialog window shows up but still have it open when the user clicks on the input?

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

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

发布评论

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

评论(5

雨落□心尘 2024-12-16 03:06:21

您可以使用图标触发器: http://jqueryui.com/demos/datepicker/#icon -trigger

并且,如果需要,阻止用户输入日期。

我用日期选择器创建了一个对话框,但无法在 FF 或 Chrome 中重复该问题。让它在 IE 中发生。

http://jsfiddle.net/458bM/2/

$(".datepicker").datepicker({
    dateFormat: 'yy-mm-dd '
});

$(".datepicker").datepicker("disable");

$("#dialog").dialog({
width: 400,
modal: true,
open: function(event, ui) {
    $(".datepicker").datepicker("enable");
    }
});

基于之前的答案:如何模糊对话框中的第一个表单输入开幕

You could use the icon trigger: http://jqueryui.com/demos/datepicker/#icon-trigger

And, if needed, prevent the user from typing in a date.

I created a fiddle of a dialog with a datepicker and couldn't duplicate the issue in FF or Chrome. Got it to happen in IE.

http://jsfiddle.net/458bM/2/

$(".datepicker").datepicker({
    dateFormat: 'yy-mm-dd '
});

$(".datepicker").datepicker("disable");

$("#dialog").dialog({
width: 400,
modal: true,
open: function(event, ui) {
    $(".datepicker").datepicker("enable");
    }
});

Based on previous answer: How to blur the first form input at the dialog opening

天涯离梦残月幽梦 2024-12-16 03:06:21

当对话框未打开时,您可以禁用日期选择器。

$('#datepicker').datepicker({ 
    ...
    disabled: true 
});

$('#dialog').dialog({
    open: function(event, ui) {
        $('#datepicker').datepicker('enable');
    },
    close: function(event, ui) {
        $('#datepicker').datepicker('disable');
    },
    ...
});

请查看实际操作:http://jsfiddle.net/william/Rf37h/1/

You can disable the datepicker when the dialog is not open.

$('#datepicker').datepicker({ 
    ...
    disabled: true 
});

$('#dialog').dialog({
    open: function(event, ui) {
        $('#datepicker').datepicker('enable');
    },
    close: function(event, ui) {
        $('#datepicker').datepicker('disable');
    },
    ...
});

See this in action: http://jsfiddle.net/william/Rf37h/1/.

去了角落 2024-12-16 03:06:21

定义对话框时,您可以指定在打开时接收焦点的元素。将焦点设置到对话框中的不同元素

$('#myDialog').dialog({
    open: function (event, ui)
        {
            $('#myInputBox').focus();
        }
});

您还可以调用隐藏打开事件代码中的日期选择器。

When you define your dialog you can specify the element to receive focus on open. Set the focus to a different element in the dialog

$('#myDialog').dialog({
    open: function (event, ui)
        {
            $('#myInputBox').focus();
        }
});

You could also put your call to hide the datepicker in the open event code.

逆光下的微笑 2024-12-16 03:06:21

试试这一行代码

$(document).ready (function () { 
 $('#dialog_modal_body').on("click", ".datepicker", function(){
       $("#ui-datepicker-div").css("z-index", "100000");
 });
});

Try This one line code

$(document).ready (function () { 
 $('#dialog_modal_body').on("click", ".datepicker", function(){
       $("#ui-datepicker-div").css("z-index", "100000");
 });
});
温馨耳语 2024-12-16 03:06:21

在它之前添加一个隐藏元素,它将尝试自动对焦。

这将使您的日期选择器在打开对话框时不会受到关注。

<span class="ui-helper-hidden-accessible"><input type="text"/>Prevents autofocus from opening start datepicker on dialog load</span>

Add a hidden element before it that it will try to autofocus to.

This will keep your datepicker from being focused on when opening the dialog.

<span class="ui-helper-hidden-accessible"><input type="text"/>Prevents autofocus from opening start datepicker on dialog load</span>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文