weixin_33712987 2012-02-27 19:42 采纳率: 0%
浏览 77

为什么图片加载不触发?

我想使用xmlhttprequest将文本和图像加载到div中,不幸的是,图像onload事件不起作用。

代码是这样的:

<img src="pic.png" onload="alert('...')"/>

请求后我可以看到图像,但是onload事件不会触发——为什么?

  • 写回答

2条回答 默认 最新

  • 衫裤跑路 2012-02-27 19:46
    关注

    Can be down to caching. The onload event for images is a bit sketchy and doesn't always fire for AJAX requests.

    Try adding a query parameter to the request with the current date to stop any caching

    评论

报告相同问题?