棋盘

使用方框和方块实现国际象棋棋盘

<!DOCTYPE html>
<html lang="zh_CN">
<head>
    <meta charset="UTF-8">
    <title>国际象棋棋盘</title>
</head>
<body>
<canvas id="canvas" width="300" height="300"></canvas>
<script>
        let canvas = document.getElementById("canvas");
        let context = canvas.getContext("2d");
        for(let j = 0; j < 4; j++){
            for(let i = 0; i < 4; i++){
                // 每四个每四个为一组画
                context.fillRect(i*80, j*80, 40, 40);
                context.fillRect(i*80+40, j*80+40, 40, 40);
                context.strokeRect(i*80+40, j*80, 40, 40);
                context.strokeRect(i*80, j*80+40, 40, 40);
            }
        }
</script>
</body>
</html>

--_050
效果如上