问答详情
源自:2-2 画棋盘

为什么我的对角线实现不了

JS代码:


var chess = document.getElementById('chees');

var context = chess.getContext('2d');


context.strokeStyle="#BFBFBF";


context.moveTo(0,0);

context.lineTo(450,450);

context.stroke();

HTML代码:

<!DOCTYPE html>

<html>

<head>

<meta charset="utf-8" />

<title>五子棋</title>

<link rel="stylesheet" href="css/style.css" />

</head>

<body>

<canvas id="chess" width="450px" height="450px"></canvas>

<script type="text/javascript" src="js/script.js" ></script>

</body>

</html>

http://img.mukewang.com/5802cba6000152f314400865.jpg

提问者:李占山 2016-10-16 08:37

个回答

  • 木念白
    2016-10-17 00:24:11
    已采纳

    var chess = document.getElementById('chees');  id取错了,是chess

  • Kingbird
    2017-02-12 02:27:58

    var chess = document.getElementById('chess');
    var context = chess.getContext('2d');
    
    context.storkeStyle = "#BFBFBF";
    
    context.moveTo(0, 0);
    context.lineTo(450, 450);
    context.storke();
    <!DOCTYPE html>
    <html>
    <head>
    <meta charset="utf-8">
    <title>五子棋</title>
    <link rel="stylesheet" type="text/css" href="css/style.css">
    </head>
    <body>
    <canvas id="chess" width="450px" height="450px"></canvas>
    <script type="text/javascript" scr="js/script.js"></script>
    </body>
    </html>
    canvas {
    	display: block;
    	margin: 50px auto;
    	box-shadow: -2px -2px 2px #EFEFEF, 5px 5px 5px #B9B9B9;
    }

    我这样也没有斜线,这是为什么,ID没错呀??