簡體   English   中英

Javascript / jQuery HasLoaded或等效版本?

[英]Javascript/jQuery HasLoaded or equivalent?

我知道在jquery中可以調用javascript / jquery onload() / load()函數,例如圖像( <img> )。

但是,如果在jQuery中,如果我在加載dom后使用.html(htmlString)插入圖像,我如何添加偵聽器來處理圖像onload事件? 有沒有可以查看各種圖像以及是否已加載的屬性?

附加html之后,您可以將load事件綁定到所包含的圖像:

$("#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");
});

檢查圖像的complete屬性

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM