html冻结在Jquery对话框



我正在开发一个客户端应用程序,我使用jquery确认对话框。它要求用户确认,如果用户选择"是",它应该关闭对话框,然后删除表中的项目。然而,我看到的是(如果用户选择"是"),应用程序正在忙着删除表项,UI被对话框确认冻结。有什么方法我可以从这个代码得到预期的响应?(意味着关闭确认对话框,然后继续执行删除操作)。注意:这不是在任何浏览器;我正在使用IE组件来加载客户端小部件中的html。

$('<div title="Confirm" class="cfmDialog" />')
        .html('<span style="float:left; margin:0 7px 20px 0;"></span>' + "Are you sure you want to delete all items in table?")
        // Define the Dialog and its properties.
        .dialog({
            resizable: false,
            modal: true,
            title: "Delete table items",
            height: 150,
            width: 300,
            buttons: {
                "Yes": function () {
                    $(this).dialog('close');
                    deleteTableItems();
                },
                "No": function () {
                    $(this).dialog('close');
                }
            }
        });

您可以在超时后运行deleteTableItems():

"Yes": function() {
    $(this).dialog("close");
    setTimeout(deleteTableItems, 1);
},

但是这仍然会在函数运行时冻结浏览器,它只会让对话框先关闭。最好的解决方案是修复deleteTableItems,使其异步运行。

最新更新