jquery ui对话框只打开一次 [英] jquery ui dialog opens only once

查看:137
本文介绍了jquery ui对话框只打开一次的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个按钮,当点击时打开一个对话框。
对话框显示一个隐藏的div

I have a button that opens a dialog when clicked. The dialog displays a div that was hidden

通过单击X图标关闭对话框后,无法再次打开对话框。

After I close the dialog by clicking the X icon, the dialog can't be opened again.

推荐答案

Scott Gonzalez(jQuery UI Team)谈到了很多人在开始使用jQuery UI时遇到这个问题的原因博文: http:// blog.nemikor.com/2009/04/08/basic-usage-of-the-jquery-ui-dialog/

Scott Gonzalez (of the jQuery UI Team) talks about the reason alot of people have this problem when getting started with jQuery UI in a recent blog post: http://blog.nemikor.com/2009/04/08/basic-usage-of-the-jquery-ui-dialog/

摘录:


用户经常遇到
对话框的问题是他们尝试
每次实例化一个新的对话框
用户执行某些操作
(通常单击链接或
按钮)。这是一个可以理解的
错误,因为乍看之下
似乎在
元素上调用.dialog()是导致对话框
打开。实际上发生的是
,一个新的对话实例正在创建
,然后该实例是

实例化之后立即打开。
对话框打开的原因是对话框有
一个autoOpen选项,默认为
true。因此,当用户在一个元素上调用.dialog()
两次时,第二次调用
被忽略,因为对话框的
已经在
元素上实例化。

The problem that users often encounter with dialogs is that they try to instantiate a new dialog every time the user performs some action (generally clicking a link or a button). This is an understandable mistake because at first glance it seems like calling .dialog() on an element is what causes the dialog to open. In reality what is happening is that a new dialog instance is being created and then that instance is being opened immediately after instantiation. The reason that the dialog opens is because dialogs have an autoOpen option, which defaults to true. So when a user calls .dialog() on an element twice, the second call is ignored because the dialog has already been instantiated on that element.

解决方案:

这个问题的简单解决方案是
实例化对话框
autoOpen set为false,然后在事件处理程序中调用
.dialog('open')。

The simple solution to this problem is to instantiate the dialog with autoOpen set to false and then call .dialog('open') in the event handler.



$(document).ready(function() {
    var $dialog = $('<div></div>')
        .html('This dialog will show every time!')
        .dialog({
            autoOpen: false,
            title: 'Basic Dialog'
        });

    $('#opener').click(function() {
        $dialog.dialog('open');
    });
});

这篇关于jquery ui对话框只打开一次的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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