头部的Javascript功能在身体中无法识别

Env*_*ite -1 javascript

为什么这段代码不起作用?

<!DOCTYPE html>
<html lang="es">
 <head>
  <title>Euroqpa</title>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <script type="type=text/javascript">
   <!--
    function drawcanvas() {
     var c=document.getElementById("myCanvas");
     var ctx=c.getContext("2d");
     ctx.fillStyle="#FF0000";
     ctx.fillRect(0,0,150,75);
    }
   //-->
  </script>
 </head>
 <body>
 <canvas id="myCanvas" width="300" height="300"></canvas>
 <script type="text/javascript">
 <!--
  drawcanvas();
 //-->
 </script>
 </body>
</html>
Run Code Online (Sandbox Code Playgroud)

我认为头部定义的函数应该被正文中的脚本识别.不是吗?

它说:未捕获的ReferenceError:未定义drawcanvas

Cla*_*edi 5

乍一看type,头部脚本上的属性是错误的

更换

<script type="type=text/javascript">
Run Code Online (Sandbox Code Playgroud)

通过

<script type="text/javascript">
Run Code Online (Sandbox Code Playgroud)