addPath()不起作用

代码:


<!DOCTYPE html>

<html>

<head>

    <title>canvas元素示例</title>

    <meta charset="utf-8">

    <script type="text/javascript">

        function draw(){

    var canvas = document.getElementById('canvas');

    if (canvas.getContext) {

        var context = canvas.getContext('2d');

        var path1 = new Path2D();

        path1.rect(10,10,100,100);

        var path2 = new Path2D();

        path2.moveTo(220,60);

        path2.arc(170,60,50,0,2*Math.PI,false);

        path2.addPath(path1);

        context.stroke(path2);

    }

}

    </script>

</head>

<body onload="draw()">

    <h1>canvas元素示例</h1>

    <canvas id="canvas" width="400" height="300"></canvas>

</body>

</html>

然后chrome提示:

https://img.mukewang.com/5c6fa3460001b71a07430564.jpg

我这看蒙了也没看出来哪里写错了,求救~

慕哥9229398
浏览 434回答 1
1回答

一只甜甜圈

FeatureChromeFirefox (Gecko)Internet ExplorerOperaSafariBasic support未实现34 (34)未实现(Yes)(Yes)
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

JavaScript