期望的行为是当文档负载,画布绘制图像0被点击无形的div时,画布绘制图像1中,在鼠标松开或鼠标移开,它将恢复到图像0改变画布图像
我离开了CSS,因为我得到了这个工作......只需要知道我在做什么错误的JavaScript函数。现在它不显示任何东西,甚至不显示第一张图像。
<!DOCTYPE HTML>
<html>
<head>
<script type="text/javascript">
function imgChange(imagePath)
var c=document.getElementById("myCanvas");
var ctx=c.getContext("2d");
var img=new Image();
img.onload = function(){
ctx.drawImage(img,0,0);
};
img.src=imagePath; <!-- I THINK THIS IS WRONG?
</script>
</head>
<body>
<canvas id="myCanvas" width="506" height="319"
onload="imgChange('0.gif')" style="border:1px solid #c3c3c3;">
Your browser does not support the canvas element.
</canvas>
<div id="button1" onMouseDown="imgChange('1.gif')" onMouseUp="imgChange('0.gif')" onMouseOut="imgChange('0.gif')"></div>
<div id="key2"></div>
</body>
</html>
第一个也不存在了! ;) – Mohsen