<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
</head>
<body>
<canvas id="canvas" style="border:1px solid #aaa;display:block;margin:50px auto;">
当前浏览器不支持Canvas,请更换浏览器后再试
</canvas>
<script>
window.onload = function(){
var canvas = document.getElementById("canvas");
canvas.width =800;
canvas.height = 800;
var context=canvas.getContext("2d");
context.moveTo=(10,10);
context.lineTo=(800,800);
context.lineWidth=10;
context.strokeStyle="red";
context.stroke();
}
</script>
</body>
</html>
context.moveTo和context.lineTo是函数, 调用方式不对
context.moveTo(10,10);
context.lineTo(800,800);
这样把等号去掉就好了