日期:2014-05-16  浏览次数:20280 次

HTML5中Canvas的小问题?????
HTML code

<!DOCTYPE html>
</html>
<head>

<title>canvas中drawImage</title>
<script>
window.addEventListener('load', function () {
    var canvas = document.getElementById('myCanvas');

  // 取得canvas 2d context.
  var context = canvas.getContext('2d');

//三个参数:图像位置,x,y在canvas中的位置
context.drawImage("image/Opera96.png", 10, 10);
// 五个参数,最后两个是宽高
context.drawImage("image/Opera96.png", 100, 10, 200, 200);

    },false);
    </script>
</head>

<body>
<div id="myCanvas" width="500" height="650">
Fallback content, in case the browser does not support Canvas.
</div>

</body>
</html>


在FireFox中:出现错误
canvas.getContext is not a function
[在此错误处中断] var context = canvas.getContext('2d'); 

在Opera浏览器中:显示了
Fallback content, in case the browser does not support Canvas.

------解决方案--------------------
<canvas id="myCanvas" width="500" height="650">
Fallback content, in case the browser does not support Canvas.
</canvas>
------解决方案--------------------
你下面又没有用CANVAS。。。当然没有方法了。
------解决方案--------------------
不是
参数 是一个image对象 或者一个canvas对象