Code: [show] | [select all]
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>Canvas</title>
</head>
<body onload="main()">
<canvas id="example1" width="400" height="400">
Please use a browser that supports "canvas"
</canvas>
<script>
function main()
{
var canvas = document.getElementById('example1');
if (! canvas )
{
console.log('Failed to retrieve the <canvas> element');
return;
}
var ctx = canvas.getContext('2d'); // 注意是小写'd'
ctx.fillStyle = 'rgba(0, 0, 255, 1.0)';
ctx.fillRect(120, 10, 150, 150);
}
</script>
</body>
</html>
http://runjs.cn/code/8r9cqjly