日期:2014-05-16 浏览次数:20379 次
<body> <canvas id='tutorial' width='150px' height='150px'></canvas> </body>
canvas{ border:2px solid #000; margin:10px; padding:10px; color:red; }
$(document).ready(function(){ draw(); }); function draw(){ var canvas = document.getElementById('tutorial'); if(canvas.getContext){ var ctx = canvas.getContext('2d'); ctx.fillRect(25, 25, 100, 100); } }
<body> <canvas id='tutorial'></canvas> </body>
canvas{ width:150px; height:150px; border:2px solid #000; margin:10px; padding:10px; color:red; }
<body> <canvas id='tutorial'></canvas> </body>
$(document).ready(function(){ draw(); }); function draw(){ var canvas = document.getElementById('tutorial'); canvas.width = 150; canvas.height = 150; if(canvas.getContext){ var ctx = canvas.getContext('2d'); ctx.fillRect(25, 25, 100, 100); } }
<html> <!--省略head代码--> <body> <canvas id='tutorial'></canvas> </body> <!--[if lt IE 9]> <script src="excanvas.min.js" type="text/javascript"></script> <![endif]--> <script src="jquery-1.5.1.min.js" type="text/javascript"></script> <script type="text/javascript"> $(document).ready(function(){ draw(); }); function draw(){ var canvas = document.getElementById('tutorial'); if(canvas.getContext){ var ctx = canvas.getContext('2d'); ctx.fillRect(25, 25, 100, 100); } } </script> </html>