日期:2014-05-17  浏览次数:20597 次

关于html5 canvas元素问题。。。
关于html5 canvas元素问题。。。

<!DOCTYPE html>
<head>
<meta charset="utf-8">
<title>canvas 元素示例</title>

</head>
<body>
<h1>canvas 元素示例</h1>
<canvas id="canvas" width="400" height="400" /> 
</body>

<script>
  function (){
var canvas = document.getElementById("canvas");
if(canvas == null)
return false;
var context = canvas.getContext("2b");
context.fillStyle = "#EEEEFF";
context.fillRect(0,0,400,400);
context.fillStyle = "red";
context.strokeStyle = "blue";
context.lineWidth = 1;
context.fillRect(50,50,100,100);
context.strokeRect(50,50,100,100);
}


</script>
</html>


为什么在火狐和欧鹏浏览器都不显示???好像js没执行。。。求解,先谢谢了!!!浏览器版本是最新的!

------解决方案--------------------
楼主很喜欢2b》???var context = canvas.getContext("2b");应该是2d ....../汗
你至少应该在你的函数前面加一个window.onload = function() {你要调用的函数}----给函数加个名字