如何获取元素的innerHTML立即更新? [英] How can I get an element's innerHTML to update immediately?

查看:315
本文介绍了如何获取元素的innerHTML立即更新?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带有文本框的网页。当在框中输入 .js 文件名并单击执行按钮时,给定的文件将通过AJAX和 eval()加载。 code>'d。

I have a web page with a text box. When entering in a .js file name into the box and clicking the Execute button, the file given will be loading via AJAX and eval()'d.

此页面上还有一个空的< div> 用作输出。如果加载的文件需要在屏幕上打印某些内容,则会将其添加到 div innerHTML 中。

Also on this page is an empty <div> for used as output. If the file that is loaded needs to print something to the screen, it adds it to the div's innerHTML.

将文本添加到 innerHTML时,通常在完成JavaScript之前不会在屏幕上呈现,这很好,除了有时Javascript文件执行繁重的计算(可能要花一分钟的时间才能完成),并且能够在执行时看到输出会很有用。

When adding text to the innerHTML, it usually doesn't render on the screen until the Javascript is completed, which is fine, except for the fact that, sometimes, the Javascript file performs heavy calculations which can take upwards to a minute to complete, and it would be useful to be able to see the output as it was executing.

有什么方法可以刷新文档吗?

Is there any way to "refresh" the document?

推荐答案

您可以使用setTimeout :

You can use setTimeout:

div.innerHTML = html;
setTimeout( function(){
   doHeavyCalculations();
}, 35);

http://jsfiddle.net/YKEKK/

这篇关于如何获取元素的innerHTML立即更新?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆