在加载对象内容时运行Javascript函数 [英] Run Javascript function when object content has been loaded

查看:78
本文介绍了在加载对象内容时运行Javascript函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当加载了< object> 的内容时,如何运行Javascript函数? c $ c> DOMContentLoaded 事件在此之前触发,而依赖它的东西就像JQuery的 $()同样。

这个。第一个示例失败,因为在外部SVG尚未加载时执行该功能。第二个例子会轮询其想要更改的元素,然后执行相关代码,并成功。



投票工作在实践中,但是是否有更好的解决方案?理想的情况是会发生一个可以使用的事件。

解决方案

使用onload DomEvent工作吗?

 < object onload =changeColor()data =circles.svgtype =image / svg + xml ID = 圆圈 >< /对象> 

看到我的 here


How do I run a Javascript function when the content of an <object> has been loaded? The DOMContentLoaded event fires before that, and things that rely on it like JQuery's $() likewise.

Compare this to this. The first example fails because the function is executed when the external SVG hasn't been loaded. The second example polls for the elements it wants to change and only then executes the relevant code, and succeeds.

Polling works in practice, but is there a better solution for this? Ideally there would be an event fired that I can use.

解决方案

Does using the onload DomEvent work?

<object onload="changeColor()" data="circles.svg" type="image/svg+xml" id="circles"></object>

see my it here

这篇关于在加载对象内容时运行Javascript函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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