jquery 1.4.2 - jquery UI对话框,外部点击关闭(不是模态) [英] jquery 1.4.2 - jquery UI dialog, close when outside click (not modal)

查看:204
本文介绍了jquery 1.4.2 - jquery UI对话框,外部点击关闭(不是模态)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用UI对话框。
jquery 1.4.2

Using UI dialog. jquery 1.4.2

我的代码在外部点​​击时关闭对话框。
这对我来说不行。但是,如果我在本地开发版本,它的工作正常。
问题是,我不能为这个网站的这个部分添加jquery版本。

I have my code to close a dialog when clicked outside. This doesn't work for me. However, if I up the version on a local development, it works fine. The issue is, that I can't up the jquery version for this part of the site.

想到如何实现点击非模态对话框关闭?

Thoughts on how to achieve clicking outside a non-modal dialog to close?

// Close Pop-in If the user clicks anywhere else on the page
             jQuery('body')
              .bind(
               'click',
               function(e){
            if(
             jQuery('.detailsPopup').dialog('isOpen')
             && !jQuery(e.target).is('.ui-dialog, a')
             && !jQuery(e.target).closest('.ui-dialog').length
            ){
             jQuery('.detailsPopup').dialog('close');
            }
               }
              );


推荐答案

您可以尝试这样:

http://jsfiddle.net/GKfZM/117/

它正在运行1.4.4,但尝试一下。 autoOpen true或false。

It is running 1.4.4 but give it a try. Works for autoOpen true or false.

$('#open').click(function() {
    $('#your-dialog-id').dialog('open');
    closedialog = 0;
});

var closedialog;

function overlayclickclose() {
    if (closedialog) {
        $('#your-dialog-id').dialog('close');
    }
    //set to one because click on dialog (focus) box sets to zero 
    closedialog = 1;
}

$('#your-dialog-id').dialog({
    autoOpen: false,
    open: function() {
        closedialog = 1;
        $(document).bind('click', overlayclickclose);
    },
    focus: function() {
        closedialog = 0;
    },
    close: function() {
        $(document).unbind('click');
    },
    buttons: {
        Submit: function() {
        $(this).dialog('close');
    }
  }
});

这篇关于jquery 1.4.2 - jquery UI对话框,外部点击关闭(不是模态)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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