代码完全复制(结果在chrome和Firefox里都报错)
代码如下
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>canvers</title> </head> <body> <canvas id="canvas" width="1075px" height="675px" style="display: block; border:1px solid #999;margin: 0 auto;"> 您的浏览器暂不支持canvas!请更换浏览器重试。 </canvas> <script type="text/javascript" > var can = document.getElementById("#canvas"); alert(can); var context = can.getContext("2d"); var myImage = new Image(); window.onload = function(){ myImage.src = "test.png"; myImage.onload = function(){ context.drawImage(myImage,50,50); }; }; </script> </body> </html>
报错如下:TypeError: can is null