【代码】
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Canvas Test</title>
<style>
#canvas {
border: 1px solid black;
}
</style>
<script>
function fun() {
with (document.getElementById('canvas').getContext('2d')) {
fillStyle = "#0000ff"; // blue
fillRect(20, 20, 150, 100);
clearRect(50, 50, 10, 10);
}
}
</script>
</head>
<body onLoad="fun()">
<canvas height="300" width="300" id="canvas" onClick="alert("You have clicked me!")"></canvas>
</body>
</html>