如何检测innerHTML何时完成 [英] How to detect when innerHTML is complete

查看:96
本文介绍了如何检测innerHTML何时完成的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经做了很多寻找这个问题的解决方案,但到目前为止还没有找到一个可以跨浏览器工作的方法。



我需要的是一个原始的javascript函数,一旦innerHTML成功插入到dom中,它将获取一个元素并运行一个回调。



例如

  var element = document.getElementById('example'); 
element.innerHTML = newhtml;

waitUntilReady(element,function(){
//在这里做东西......
});

总而言之,我需要能够检查元素的内容并触发回调innerHTML完成时。



提前感谢您的帮助。

解决方案

不需要这样的功能。在继续运行任何脚本之前,分配给 innerHTML 将立即执行此操作。



如果您确实需要延迟执行(说允许浏览器重绘),使用 setTimeout ,延迟为 1 (或其他短暂间隔)。 / p>

I've done quite a bit of searching for a solution to this problem but so far haven't found one that works cross browser.

What I need is a raw javascript function which will take an element and run a callback once the innerHTML has successfully been inserted into the dom.

e.g.

    var element = document.getElementById('example');
        element.innerHTML = newhtml;

    waitUntilReady(element, function(){
            //do stuff here...
    });

So just to summarize, I need to be able to check the contents of the element and fire a callback when innerHTML has completed.

Thanks in advance for any help.

解决方案

There is no need for such a function. Assigning to innerHTML will do so immediately before continuing to run any scripts.

If you really need to delay execution (say to allow the browser to redraw), use setTimeout with a delay of 1 (or other short interval).

这篇关于如何检测innerHTML何时完成的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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