<body>
<canvas id="canvas" style="border:1px solid grey;display:block;margin:50px auto"></canvas>
<script>
window.onload=function(){
var canvas=Document.getElementById('canvas');
canvas.width=1024;
canvas.height=768;
if(canvas.getContext('2d')){
var context=canvas.getContext('2d')
//开始绘图
}
else{
alert("请更换浏览器");
}
}
</script>
</body>
<canvas id="canvas" style="border:1px solid grey;display:block;margin:50px auto"></canvas>在这里面设置大小
在<canvas>里也要定义width,height