[removed] onload and onerror called together

后端 未结 2 1251
我寻月下人不归
我寻月下人不归 2021-01-01 06:15

I\'m new to JavaScript and therefore confused for the variable scope... I\'m trying to load an image, and replace it with another URL when it doesn\'t exist. I have to do it

2条回答
  •  借酒劲吻你
    2021-01-01 06:40

    You are calling the functions, not assigning!

    img.onload = onLoadHandler();
    img.onerror = onErrorHandler();
    

    needs to be

    img.onload = onLoadHandler;
    img.onerror = onErrorHandler;
    

提交回复
热议问题