简体   繁体   English

在功能完成之前,屏幕不会重新粉刷

[英]Screen not repainted until function completed

Please look at the following code: 请看下面的代码:

...
$(document.documentElement).append("<div id='suggestContainer'>Loading...</div>");
$("#suggestContainer").css({
    border: "1px solid black",
    position: "absolute",
    display: "block",
    left: 100,
    top: 100,
    height:100
});
//alert("test");
TimeConsumingFunction();
...

The problem: suggestContainer element won't display in the document until TimeConsumingFunction call is completed. 问题:直到TimeConsumingFunction调用完成后,才会在文档中显示proposalContainer元素。 If I uncomment alert(test) before TimeConsumingFunction call, alert dialog shows up and I can see suggestionContainer element displayed. 如果我在TimeConsumingFunction调用之前取消对alert(test)的注释,则将显示警报对话框,并且可以看到显示的proposalcontainer元素。

Why is this happening? 为什么会这样呢? I tried IE and Chrome and it works the same. 我尝试了IE和Chrome,它的工作原理相同。 Is there way to flush HTML and force changes to be displayed? 有没有办法刷新HTML并强制显示更改?

Thanks 谢谢

I think it is happening because you are appending the div and just after that adding the css so may be it is not loaded to DOM properly.After css added use setTimeout for a sec then call TimeConsumingFunction(); 我认为这是因为您要追加div,然后再添加css,所以可能未正确将其加载到DOM。添加css之后,请使用setTimeout一秒钟,然后调用TimeConsumingFunction(); or use the css in the div itself ie inline. 或在div本身即内联中使用CSS。

setTimeout(function(){ TimeConsumingFunction() },100); 

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

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