이 갈주십시오. 나는 그것이 얼마나 유용 모르겠지만, 땜질 같은 느낌과는 다소 타사가 의도적으로 지연 통합함으로써 시나리오를 차지한다 :
$(document).ready(function() {
// match an image with specific dimension, return it
function imgNinja() {
var $img = $("img").filter(function() {
return ($(this).height() == 1 && $(this).width() == 1);
});
return $img;
}
// periodically execute this to check for matches
function keepSeeking() {
$img = imgNinja();
if($img.length) {
alert('found it');
clearInterval(i);
// do something with image
}
}
// insert a fake into the DOM at a bit of an interval
function addNastyImage() {
var $invader = $('<img src="foo.jpg" height="1px" width="1px"/>');
$('html').append($invader);
}
setTimeout(addNastyImage, 5000);
var i = setInterval(keepSeeking, 1000);
});
데모 : http://jsfiddle.net/NyEdE/3/
어떻게해야할지 모르지만 실제로 사용해 보셨습니까? $ ('img'). live ('load', function() {alert ("DOM에 이미지가 추가되었습니다!");}); – Adam
@ Adam : 페이지가 말 그대로 수백 개의 이미지를 가질 수 있다는 점을 고려하면 짧은 순서로 미칠 수 있다고 확신합니다. – Robusto
@Robusto True이지만 클래스, ID, src 또는 크기별로 선택기를 필터링 할 수 있습니다.로드 이벤트를 첨부하기 위해 라이브를 사용하는 것이 좋았지 만 이미지가 DOM에 추가 될 때 호출되는지 여부는 확실하지 않습니다. 그렇다면 언제. – Adam