如何在纯JavaScript中重新创建以下代码?
$('#img').on('load error', function() { something(); });
答案 0 :(得分:0)
试试这个:
<img id="image" src="image.gif" onerror="myFunction()">
或内联:
document.getElementById("image").addEventListener("error", function(){ something(); });
document.getElementById("image").src = filename;
或从头开始:
var img=new Image();
img.onload=function(e) { somethingGood(); };
img.onerror=function(e) { somethingBad(); };
img.src=URL;