jQuery对话框,点击外面关闭 [英] jQuery Dialog, closing when click outside

查看:136
本文介绍了jQuery对话框,点击外面关闭的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道我可以使用以下内容来关闭对话框:

I know I can use the following to close the dialog box by clicking outside:

$('.ui-widget-overlay').click(function() { $("#dialog").dialog("close"); });

但是,如何更改这个对每个对话框都有效,就是说要关闭任何对话框,因为我们在页面上有多个,并且更容易有一行代码?

But how do I change this so it works for every dialog box, ie I want to say close any dialog box as we have multiple on a page and would be easier to have one line of code?

推荐答案

也许这是过分的,但是尝试

Maybe this is overkill, but try

$('.ui-widget-overlay').live('click',
    function() {
        $(".ui-dialog").dialog("close");
    }
);

您只需在页面上运行一次代码, live 方法应该使您的任何时候打开一个对话框。

You only need to run this code once on your page, the live method should make it work any time you open a dialog.

编辑:如果这不工作,它可能是 .dialog 的错误。尝试

If this isn't working, it might be .dialog's fault. Try

$('.ui-widget-overlay').live('click',
    function() {
        $(".ui-dialog").each(
            function() {
               $(this).dialog("close");
            }
        );
    }
);

这篇关于jQuery对话框,点击外面关闭的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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