如何在javascript中绘制方块-LMLPHP

本文操作环境:windows7系统、javascript1.8.5&&html5版、Dell G3电脑。

html中插入javascript画矩形

<!DOCTYPE <!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"/>
<title>canvas元素示例</title>
<script>
function draw(id)
{
var canvas = document.getElementById(id);
if(canvas == null)
return false;
var context = canvas.getContext('2d');
context.fillStyle = "#eeefff";
context.fillRect(0,0,400,300);
context.fillStyle = "green";
context.strokeStyle = "red";
context.lineWidth = 1;
context.fillRect(50,50,100,100);
context.strokeRect(50,50,100,100);
}
</script>
</head>
<body οnlοad="draw('canvas');">
<h1>canvas中画矩形</h1>
<canvas id="canvas" width="400" height="300"/>
</body>
</html>
登录后复制

如何在javascript中绘制方块-LMLPHP

【推荐学习:javascript高级教程

以上就是如何在javascript中绘制方块的详细内容,更多请关注Work网其它相关文章!

09-16 23:30