jQuery/Javascript - How to wait for manipulated DOM to update before proceeding with function

后端 未结 4 683
[愿得一人]
[愿得一人] 2020-11-30 07:16

What I\'m trying to do is to update a simple div to say \"Processing...\" before executing a CPU-intensive script (it takes 3-12 seconds to run, no AJAX) then update the div

4条回答
  •  盖世英雄少女心
    2020-11-30 08:09

    set it to processing, then do a setTimeout to prevent the cpu intensive task from running until after the div has been updated.

    
    
    
    
    
        
    
        
    Not Started
    javascript

    you can modify the setTimeout delay as needed, it may need to be larger for slower machines/browsers.

    Edit:

    You could also use an alert or a confirm dialog to allow the page time to update.

    document.getElementById('msg').innerHTML = 'Processing JS...';
    if ( confirm( "This task may take several seconds. Do you wish to continue?" ) ) {
         // run code here
    }
    

提交回复
热议问题