87,917
社区成员
发帖
与我相关
我的任务
分享
<!DOCTYPE html> <html>
<head>
<script type="text/javascript">
function draw() {
var canvas = document.getElementById("MyCanvas");
if (canvas.getContext) {
var ctx = canvas.getContext("2d");
ctx.beginPath();
ctx.strokeStyle = "green"; // Use strokeStyle to set the color.
ctx.rect(5, 5, 300, 250);
ctx.stroke();
ctx.beginPath();
ctx.strokeStyle = "blue"; // Use strokeStyle to change the color.
ctx.lineWidth = "5";
ctx.moveTo(100, 100);
ctx.lineTo(130, 100);
ctx.stroke();
ctx.beginPath();
ctx.strokeStyle = "red";
ctx.moveTo(170, 100);
ctx.lineTo(200, 100);
ctx.stroke();
}
}
</script>
</head>
<body onload="draw();">
<canvas id="MyCanvas" width="600" height="600"> </canvas>
</body>
</html>