简体   繁体   English

如何检测innerHTML何时完成

[英]How to detect when innerHTML is complete

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. 我需要的是一个原始的javascript函数,它将获取一个元素并在innerHTML成功插入dom后运行回调。

eg 例如

    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. 总而言之,我需要能够检查元素的内容并在innerHTML完成时触发回调。

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. 在继续运行任何脚本之前,分配给innerHTML将立即执行此操作。

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). 如果您确实需要延迟执行(比如允许浏览器重绘),请使用延迟为1 (或其他短间隔)的setTimeout

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

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