HTML5のキャンバスに赤い四角形を描画しようとしています。ここに私のHTMLがあります。ここでHTML5キャンバスに四角形を描けないのはなぜですか?
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset=utf-8>
<title>My Canvas Experiment</title>
<link rel="stylesheet" type="text/css" href="main.css" />
<script src="plotting.js"></script>
<!--[if IE]>
<script src="http://html5shiv.googlecode.com/svn/trunk/html5.js">
</script>
<![endif]-->
</head>
<body>
<canvas id="plot"></canvas>
</body>
</html>
はplotting.jsです:
ここdocument.onload = function() {
var c = document.getElementById("plot");
var ctx = c.getContext("2d");
ctx.fillStyle("#f00");
ctx.fillRect(0, 0, 175, 40);
}
があるmain.cssです:
body { margin:100px; }
article, aside, figure, footer, header, hgroup, menu, nav, section {
display:block;
}
#plot {
width: 500px;
height: 400px;
}
なぜページが空白のですか? Chromeウェブデベロッパーコンソールでエラーは発生しません。
あなたはDOMを検査するとき、あなたが何を見ていますか?あなたもonreadyを試してみたいかもしれません... – hvgotcodes
私はChromeで実行し、コンソールでエラーが発生しました。 'Uncaught TypeError:オブジェクト#のプロパティ 'fillStyle'は関数ではありません。 http://jsfiddle.net/fhEjR/ –
ありがとうございますが、 'ctx.fillStyle ="#f00 ";'を使用しても矩形が表示されません。 'onready'も使用しません。 DOMの検査方法を教えてください。 – dangerChihuahua007