Javascript/jQuery HasLoaded 或等价物?

标签 javascript jquery fsevents

我知道在 jquery 中可以调用 javascript/jquery onload()/load()功能,例如图像(<img>)。

但是,如果我在 jquery 中使用 .html(htmlString)要在 dom 加载后插入图像,如何添加监听器来处理图像 onload 事件?是否有我可以检查的属性以查看各种图像以及它们是否已加载?

最佳答案

附加 html 后,您可以将加载事件绑定(bind)到包含的图像:

$("#foo").html(htmlString).find("img").one("load", function() {
    ...
}).each(function() {

    // image has been cached, so load event won't fire unless we explicitly call it
    if(this.complete) $(this).trigger("load");
});

关于Javascript/jQuery HasLoaded 或等价物?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2850011/

相关文章:

javascript - 更改jquery中元素的id?

javascript - 不变的JS参数不清楚

jquery - 如何查找包含多个字符串的 href

javascript - 根据变量名称调用 jQuery 自动完成小部件函数

cocoa - 监视目录中的文件更改

ruby - 为什么mac下Ruby下有很多 "fsevent_watch"的实例?

node.js - 无法在ubuntu中安装yarn(fsevents@1.2.4 : The platform "linux" is incompatible with this module)

javascript - Javascript (D3) - 日期比较返回 NaN

javascript - Emscripten 可以将 LLVM 编译成 JavaScript 吗?

javascript - 获取存储在隐藏输入中的对象数组