编辑下面的代码:【加编码】
<html> <body> <p>该实例演示了如何使用 addEventListener() 方法向 img 元素中添加 "onerror" 事件。</p> <img id="myImg" src="/demo/image.gif"> <p id="demo"></p> <script> document.getElementById("myImg").addEventListener("error", myFunction); function myFunction() { document.getElementById("demo").innerHTML = "无法加载图片。"; } </script> </body> </html>
结果: 【此窗口】 帮助?
Try it Yourself - © 自强学堂