<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>Document</title>
</head>
<body>
	<img src="./images/3.jpg" alt="" width="500" id="img">
	
</body>
<script>
var img = document.getElementById('img');
img.onload = function(){
	//alert('图片加载成功');
}
img.onerror = function(){
	//alert('图片加载失败')
	img.src="./images/2.jpg";
}
</script>
</html>点击 "运行实例" 按钮查看在线实例
                Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号