简体   繁体   English

外部单击时如何关闭easyui对话框?

[英]How to close easyui dialog when click outside?

In my project, I use easyui dialog. 在我的项目中,我使用easyui对话框。

I choose easyui-linkbutton to open dialog successfully. 我选择easyui-linkbutton成功打开对话框。

Because it has no title, I want to close this dialog when clicking outside. 因为它没有标题,所以我想在外部单击时关闭此对话框。

I don't know how to define. 我不知道该怎么定义。

Here is my js code: 这是我的js代码:

<script>
$(document).ready(function()
{ 
   $('#dlg').window('close');
});
</script>

Here is my html code: 这是我的html代码:

<div class="easyui-panel" style="padding:5px;">
<a href="javascript:void(0)" class="easyui-linkbutton" onclick="$('#dlg').dialog('open')" data-options="plain:true,iconCls:'icon-newfile'">addNewFile</a>
 </div>

<div  id="dlg" class="easyui-dialog"  title=""  data-options="iconCls:'icon-save'" style="width:88px;height:260px;top:160px;left:176px;padding:10px">
<label style="cursor:pointer">one</label><br />
<label style="cursor:pointer">two</label><br />
<label style="cursor:pointer">three</label>
</div>

Who can help me ? 谁能帮我 ?

try this one also and share the information if not work.write this code on document load. 也可以尝试使用此代码,如果无法使用则共享信息。在文档加载时编写此代码。

$(document).mousedown(function(e) {
                    var clicked = $(e.target);                 
                    if (clicked.is('#dlg') || clicked.parents().is('.ui-widget-content') || clicked.is('.ui-dialog')) {                     
                        return;
                    } else { 
                        $('#dlg').dialog("close");
                    }
                });
          });

Try once may this help. 请尝试一次,可能会有帮助。

$('#dlg' ).bind('clickoutside',function(){
    $('#dlg' ).dialog('close');
});
$('#dlg' ).dialog({
    clickOutside:true,
});

I have tested, it works fail. 我已经测试过,它的工作失败了。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM