gpt4 book ai didi

javascript - 将 .live() 用于 iFrame.load() 事件?

转载 作者:塔克拉玛干 更新时间:2023-11-02 21:21:32 24 4
gpt4 key购买 nike

我知道 iFrame 通过我页面某处的 javascript 添加到我的页面,我想在它加载时收到通知,但这不起作用:

$("iframe").live("load",
function () {
alert(this.name + ": Im loaded!");
});

没有显示警报
知道为什么吗?知道我们如何才能做到这一点吗?

最佳答案

我认为您可以在将 iframe 添加到页面后进行回调。如前所述 here ,不可能将 live() 绑定(bind)到 iframe load()。

Note: The .live() and .delegate() methods cannot be used to detect the load event of an iframe. The load event does not correctly bubble up the parent document and the event.target isn't set by Firefox, IE9 or Chrome, which is required to do event delegation.

所以在你的回调中,你必须调用它,也许设置一个超时以确保它在 iframe 加载后触发。

$("iframe").load(function () {
alert(this.name + ": Im loaded!");
});

关于javascript - 将 .live() 用于 iFrame.load() 事件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6953610/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com