-2

场景:- 我正在尝试使用电话间隙框架制作 iPhone 应用程序,使用 HTML 5 Canvas 我试图将图像放在画布内,但它给出了一个奇怪的错误“绘制(匿名函数)加载”。请帮我解决一下情况。是否可以在一张画布上放置尽可能多的图像?请建议这背后的方法?

<!DOCTYPE HTML>
 <html>
<head>
    <title>TestingCanvas</title>
    <meta http-equiv="content-type" content="text/html; charset=utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=0.5, minimum-                    scale=1.0, maximum-scale=1.6" />   
    <meta name="apple-mobile-web-app-capable" content="YES" />
    <link rel="stylesheet" href="main.css" />
    <!--<script type="text/javascript" src="phonegap-1.0.0.js"></script>-->
    <!--<script type="text/javascript" src="main.js"></script>-->
        <style type="text/css" media="screen">
        canvas,img { 
            display:block; 
            margin:0px auto; 
            border:1px solid black;
        }
        canvas { 
            background:url(Images/chooser-2x2-background.png);
        }
        </style>

    <script>
        function draw()
        {   
            var canvas = document.getElementById("mycanvas");
            var ctx=canvas.getContext("2d");

            var img1 = new Image();
            img1.src = "Images/Icon-Help.png";
            img1.onload = function(){
                ctx.drawImage(img1,15,10);
            }

            var img2 = new Image();
            img2.src = "Images/Icon-Route.png";
            img2.onload = function(){
                ctx.drawImage(img2,250,10);
            }   
            var img3= new Image();
            img3.src = "Image/Icon-Call.png";
            img3.onload = function(){
            alert('lolkyb');
                ctx.drawImage(img3,400,10);
            }

            var img4= new Image();
            img4.src = "Image/Icon-Weather.png";
            img4.onload = function(){
                ctx.drawImage(img4,600,10);
            }


        </script> 
</head>
<body onload="draw()">
    <div id="canvasArea">
        <canvas id="mycanvas" width="4096 " height="300" ></canvas>
        <!--<img style="display:none" src="Images/Icon-Assist.png" id="Assist"  />
         <img style="display:none" src="Images/Icon-Trip.png" id="Trip" />
         <img style="display:none" src="Images/Icon-Training.png" id="Training" />
         <img style="display:none" src="Images/Icon-Map.png" id="Map" />
         <!--<img style="display:none" src="Images/chooser-2x2-background" width="160" height="420" id="frame"> -->
    </div>
</body>

它给出的错误:- 绘制(匿名函数)加载!请帮帮我..提前非常感谢:)*

4

1 回答 1

4

添加}关闭draw功能。

于 2012-04-05T12:13:30.083 回答