简体   繁体   中英

image onload event not firing

Should this work?

<script type=text/javascript>

    function load_i () {
        img = new Image();
        img.onload = load_e();
        img.src = "whatever.jpg";
    }

    function load_e() { alert("loaded"); }

</script>

Right now the image gets loaded, but apparently the onload event isn't being triggered. Tried it in FF and Chrome.

change:

img.onload = load_e();

to:

img.onload = load_e;

With the following line:

img.onload = load_e();

You're calling load_e and assigning the result, undefined , to img.onload .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM