简体   繁体   English

在执行JavaScript代码时显示div

[英]Showing div while javascript code is executing

I have a div that I need to show during javascript code execution: 我在javascript代码执行期间需要显示一个div:

ShowLoadingBar = function() {
    $('#loading').dialog({
        modal: true,
        resizable: false,
        draggable: false,
        width: 250,
        height: 60,
        title: "Processing...",
    });
    $(".ui-dialog-titlebar-close").attr("style","display:none");
}

But when calling this it does not display while javascript is executing. 但是,当调用它时,它不会在javascript执行时显示。 How do I fix this? 我该如何解决?

Javascript executes the code sequentially. Javascript顺序执行代码。 You don't have multiple threads or something... 您没有多个线程或其他东西...

So if you want to display something and then run some js processing or ajax call, run the code to display the dialog first! 因此,如果要显示某些内容然后运行一些js处理或ajax调用,请运行代码以首先显示对话框!

If this doesn't help, try setTimeout(...), this should actually enable you to run something asynchronous to the normal execution. 如果这样做没有帮助,请尝试使用setTimeout(...),这实际上应该使您能够运行与常规执行异步的操作。

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

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