3
我使用picture
元素與source
來選擇要加載的圖像。雖然我可以添加load
聽衆,但我無法弄清楚哪個圖像已加載,因爲img
標籤的src
屬性和屬性都是空的,即使在加載時也是如此!使用圖片時,source和srcset如何檢查哪個src被加載? (img.src爲空)
<picture>
<source srcset="images/test1.png" media="(min-width: 64em)">
<source srcset="images/test2.png" media="(max-width: 63.99em)">
<!-- This will alert an empty string "" -->
<img srcset="images/test.png" alt="" onload="alert(this.src);">
</picture>
如何確定裝載了哪個圖像?