jQuery UI对话框:在外部单击时如何关闭对话框?

编程入门 行业动态 更新时间:2024-10-25 16:29:03
本文介绍了jQuery UI对话框:在外部单击时如何关闭对话框?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

在文档中,我没有看到此类信息.

In docs I didn't see such information.

在这种情况下,有一些关闭对话框的选项:

There are options to close dialog in such cases:

1)按下Esc;

2)单击对话框中的确定"或关闭"按钮.

2) click on "OK" or "Close" buttons in the dialog.

但是如果在外部单击,如何关闭对话框?

But how to close dialog if click outside?

谢谢!

推荐答案

以下是非模式对话框的其他2种解决方案:

Here are 2 other solutions for non-modal dialogs:

如果对话框为非模态方法1: 方法1: jsfiddle/jasonday/xpkFf/

If dialog is non-modal Method 1: method 1: jsfiddle/jasonday/xpkFf/

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

非模态对话框方法2: jsfiddle/jasonday/eccKr/

Non-Modal dialog Method 2: jsfiddle/jasonday/eccKr/

$(function() { $( "#dialog" ).dialog({ autoOpen: false, minHeight: 100, width: 342, draggable: true, resizable: false, modal: false, closeText: 'Close', open: function() { closedialog = 1; $(document).bind('click', overlayclickclose); }, focus: function() { closedialog = 0; }, close: function() { $(document).unbind('click'); } }); $('#linkID').click(function() { $('#dialog').dialog('open'); closedialog = 0; }); var closedialog; function overlayclickclose() { if (closedialog) { $('#dialog').dialog('close'); } //set to one because click on dialog box sets to zero closedialog = 1; } });

更多推荐

jQuery UI对话框:在外部单击时如何关闭对话框?

本文发布于:2023-08-06 13:15:44,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1312638.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:对话框   单击   jQuery   UI

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!