检测img src更改 [英] Detect a img src change
问题描述
我试图检测图像的来源是否已更改。
I'am trying to detect if the source of a image is changed.
在我的情况下,src从jquery更改,我无权更改jquery文件。
所以我试图从img元素中检测src更改。
In my case the src is changed from jquery, and i have no right's to change the jquery file. So im trying to detect the src change from a img element.
我想看看源代码是否更改src,仅用于测试
I would like to see the source if the src is changed, just for testing
这是我目前的代码:
var divimg = document.getElementById("img_div");
divimg.onchange = alert(divimg.getElementsByTagName('img')[0].src);
在页面上加载警报反应并显示src,但不显示src从jquery更改
On the page load the alert react's and shows me the src, but not on a src change from jquery
推荐答案
DOMAttrModified
可能有效,不知道这个...但是onload对我来说绝对没问题。这是演示的小提琴。 http://jsfiddle.net/QVqhz/
DOMAttrModified
might work, no idea about that...but onload works definitely fine for me. Here's the fiddle with the demo. http://jsfiddle.net/QVqhz/
这篇关于检测img src更改的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!