0

为什么 clickoutside 触发得太早了?对话框被此事件打开然后关闭,因此用户甚至看不到对话框

setTimeout()随附它可以工作。

$(".haspopup").click(function () {
    var id = $(this).attr("data-dialogid");
    var dlg = $("#" + id);
    // reopen dialog
    if ($(this).data("hasDlg")) {
        dlg.dialog("open");
    }

    // init dialog
    else {
        // move caption to dialog's title
        var title = "search and filter";
        if (dlg.find(".title")) {
            title = dlg.find(".title").html();
            dlg.find(".title").remove();
        }

        // add dialog
        dlg.dialog({
            position: {
                my: "left top",
                at: "left top",
                of: $(this)
            },
            width: "auto",
            resizable: false,
            title: title
        });

        $(this).data("hasDlg", true);
        // close dialog after click
        dlg.find(".lt-sort,.lt-search").click(function () {
            dlg.dialog("close");
        });

        // close dialog after click outside
        setTimeout(function () {
            dlg.bind("clickoutside", function () {
                dlg.dialog("close");
            });
        }, 500);
    }
});

任何提示?

4

0 回答 0