如何从间隔内关闭jQuery UI对话框?

问题描述

| 我正在尝试从一定间隔内关闭jQuery UI对话框。我所看到的似乎应该起作用,但是由于某种原因它不会起作用。我在模态窗口内的进度栏动画上遇到了一些麻烦,但是弄明白了。既然那不想动画普通方式,我想知道对话框是否也不想关闭普通方式。 注意:总是使其变为“ Made it!”。
    if(data.version != localStorage.getItem(\"Sync Version\")) {
        //Start the progress bar.
        $(\"#progress-bar\").progressbar({
            value:0,complete : function(event,ui) {
                $(\"#modal-message\").dialog(\"close\");
            }
        });

        //Modal Width
        modalWidth = 400;

        //Throw up a modal.
        $(\"#modal-message\").dialog({
            height: 300,width: modalWidth,modal: true
        });

        //Queries to execute on initial sync.
        qt = 0;
        queryThreshold = 4000;

        //Start the interval
        $(function() {
            var progress = setInterval(function() {
                var qval = Math.floor(100*(qt / queryThreshold));

                if (qval == 100) {
                    console.log(\"Made it!\");
                    $(\"#modal-message\").dialog(\"close\");
                    clearInterval(progress);
                } else {
                    //$(\"#progress-bar\").progressbar(\"option\",\"value\",qval);
                    $(\"#progress-bar .ui-progressbar-value\").animate({width : qval+\"%\"},modalWidth);
                }_
            },750);
        });

        //Save the newest sync verison.
        localStorage.setItem(\"Sync Version\",data.version);

        //Perform a full sync.
        full_sync();
    }
    

解决方法

加载DOM后,您是否会调用此代码?我认为so1ѭ和
$(\"#modal-message\").dialog({ /*...*/ });
可能实际上没有做任何事情。 也就是说,请尝试将对话框存储在这样的变量中:
var mydialog = $(\"#modal-message\").dialog({
然后在您的函数中引用它:
//$(\"#modal-message\").dialog(\"close\");
//becomes:
mydialog.dialog(\"close\");
    ,尝试把:
    $(\"#modal-message\").dialog({
        height: 300,width: modalWidth,modal: true
    });
在ѭ6里面