If the onload has already occurred once, will the event trigger once again when replacing src ?

  • one
    Yes. - RubaXa 5:56 pm
  • one
    And you just can not test? - Indev

2 answers 2

Doctorate

  • it was impossible to do less hard? - zb '
  • docosane oxyoma - 11111000000

That's right! Uploading an image is considered downloading a picture. By the way, if the picture is not available, the event will not work.

 var onImageLoad = function() { document .getElementById('text') .innerHTML += '<p>Image Loaded</p>'; }; var changeImageSrc = function() { var rand = Math.round((Math.random() * 200)); document .getElementById('image') .setAttribute('src', 'http://lorempixel.com/' + rand + '/' + rand); }; 
 <div> <img id="image" src="http://lorempixel.com/200/200" onload="onImageLoad();" /> </div> <div id="text"></div> <a href="#" href="" onclick="changeImageSrc(); return false">Поменять src картинки</a>