HTML5 Canvas,excanvas.js和IE.文本未在IE7中显示

Joh*_*n R 1 javascript html5 canvas

这个简单的Canvas脚本创建了一个带边框和文本的矩形.它适用于Chrome和FireFox.但该文本在Internet Explorer 7.0中不起作用.我收录了excanvas.js; 因此,矩形和边框显示在IE 7中.但是,文本没有出现在IE 7中.我想知道是否有可能让这个简单的脚本在IE 7和8中工作?

<!DOCTYPE html> 
<html lang="en">
<head>
    <link href = "style.css" type = "text/css" rel = "stylesheet" />
    <script src="js/excanvas.js" type="text/javascript"></script>

    <script type="text/javascript"> 
    function addBox(){
        var c = document.getElementById("myCanvas");
        context=c.getContext("2d"); 

        //Inner rectangle with shadow
        context.fillStyle = 'red';
        context.shadowColor="brown";
        context.shadowBlur = 20;
        context.fillRect(402,227,96.5,48.5); 
        context.shadowColor = null; 
        context.shadowBlur = null;      

        //Outer Rectangle
        context.lineWidth = '5';
        context.strokeStyle='green';    
        context.strokeRect(400,225,100,50); //draws just the edges of a rectangle               

        //font
        context.font = '17px Arial';        
        context.textBaseline = 'top';  
        context.fillStyle    = 'black';
        context.fillText  ('hello', 433, 243);
    }

    </script>
</head>

<body onload="addBox()"> 

    <canvas id="myCanvas" width="900" height="500">Your browser does not support the canvas element.</canvas> <br />
    <script type="text/javascript">     
        c = document.getElementById("myCanvas"); 
        cxt4=c.getContext("2d");
        resetCanvas();
    </script>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)

小智 6

我刚试过这个,并得到了相同的结果.然后我发现我正在使用早期版本的excanvas.使用此版本再次运行代码,它在IE8中运行.没有在IE7上测试过但运气好的话它会起作用.

史蒂夫