87,909
社区成员
发帖
与我相关
我的任务
分享
<!DOCTYPE HTML>
<html>
<head>
<title>ggg</title>
</head>
<canvas id="ground" width="640" height="560" onmousedown="mouseDown()">
</canvas>
<body onLoad="load()">
<script type="text/javascript">
var beauty;
var mycv = document.getElementById("ground");
mycv.addEventListener("onmousedown",mouseDown,false);
var myctx = mycv.getContext("2d");
function drawBeauty(beauty,x,y){
myctx.drawImage(beauty, x,y);
}
function mouseDown(e){
e=e||window.event;
drawBeauty(beauty, e.clientX, e.clientY);}
function load(){
beauty = new Image();
beauty.src = "bd.gif";
myctx.drawImage(beauty);
}
//load
</script>
</body>
</html>
mycv.addEventListener("mousedown",mouseDown,false);
IE 用attachEvent方法 这时事件名前面加on
mycv.attachEvent("onmousedown",mouseDown);