你如何测试模态jquery对话框失去焦点?

zlo*_*log 1 javascript jquery dialog

我想在你点击对话框外面时关闭对话框,但我不确定你是如何在jquery/plain javascript中测试它的.

有些人建议使用blur事件,但jquery对话框似乎不支持这种情况.


编辑我也有这个问题,但不能用任何当前提供的答案,因为我不能使我的对话框模态.

我需要这个,这样我才能在对话框最顶层时注册关键处理程序,并在另一个对话框被置于顶部时立即取消注册.

有没有人有一个解决方案 - 理想情况下,每当其他一些对话框出现时,会导致事件被提升?

mar*_*ero 10

纯jQueryUI没有模态对话框.

例:

http://jsfiddle.net/marcosfromero/x4GXy/

码:

// Bind the click event to window
$(window).click(function(event) {
    if (($(event.target).closest('.ui-dialog')).length>0) {
        // if clicked on a dialog, do nothing
        return false;
    } else {
        // if clicked outside the dialog, close it
        // jQuery-UI dialog adds ui-dialog-content class to the dialog element.
        // with the following selector, we are sure that any visible dialog is closed.
        $('.ui-dialog-content:visible').dialog('close');

    }
})
Run Code Online (Sandbox Code Playgroud)


Sto*_*bor 5

你能用你的对话模态吗?如果是这样,那么你可以(可能)通过模态覆盖上的事件实现你所追求的......

完全hacky,未经考验的想法,但它可能只是工作......

模态对话框创建名为click.dialog-overlay等的事件...在模式覆盖上单击对话框外部的鼠标时会触发这些事件.挂钩这些事件并关闭对话框可能只是做你想要做的事情......