<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>菜鸟教程(runoob.com)</title>
</head>
<body>
<img src="../images/img_lamp.jpg" id="lamp">
<canvas id="myCanvas" width="300" height="150" style="border:1px solid #d3d3d3;">
您的浏览器不支持 HTML5 canvas 标签。
</canvas>
<script>
var c = document.getElementById("myCanvas");
var ctx = c.getContext("2d");
ctx.clearRect(0, 0, c.width, c.height);
var img = document.getElementById("lamp")
var pat = ctx.createPattern(img, 'repeat');
ctx.rect(0, 0, 220, 128);
ctx.fillStyle = pat;
ctx.fill();
</script>
</body>
</html>
为什么上面这段代码执行后,画布里没有效果呢?