<!Doctype html>
<html lang = "en">
<head>
<title>HTML 5 Canvas</title>
<meta charset = "utf 8">
<script type = "text/javascript">
var canvasOne = document.getElementById("canvasOne");
var context = theCanvas.getContext("2d");
</script>
</head>
<body>
<canvas id = "canvasOne" width = "500" height ="300">
context.fillStyle = "#ffffaa";
context.fillRect(0,0,500,300);
</canvas>
</body>
</html>
如果有人可以发布一些工作代码以便我正确实现“黄色填充画布”,将非常感激。感谢
答案 0 :(得分:1)
试试这个:
<!Doctype html>
<html lang = "en">
<head>
<title>HTML 5 Canvas</title>
<meta charset = "utf 8">
</head>
<body>
<canvas id = "canvasOne" width = "500" height ="300"></canvas>
<script>
var canvasOne = document.getElementById("canvasOne");
var context = canvasOne.getContext("2d");
context.fillStyle = "#ffffaa";
context.fillRect(0,0,500,300);
</script>
</body>
</html>
答案 1 :(得分:0)
因为您将JavaScript指令放在<canvas>
内,而不是放在<script>
内。