【问题标题】:Uncaught ReferenceError: function is not defined onSVGLoad未捕获的 ReferenceError:函数未在 SVGLoad 上定义
【发布时间】:2020-12-17 11:58:45
【问题描述】:

我不知道为什么会这样,但是当我有的时候:

<svg xmlns="http://www.w3.org/2000/svg"
 viewBox="0 0 30 20"
 onload="makeDraggable(evt)">
 </svg>

我收到了这个错误:

Uncaught ReferenceError: makeDraggable is not defined
    onSVGLoad

但是当我把它改成:

    <svg xmlns="http://www.w3.org/2000/svg"
 viewBox="0 0 30 20"
 onload="makeDraggable(evt)">
<script type="text/javascript">
</script>
</svg>

错误消失了。

更新 这是我的完整 html 代码:

<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Garden Tracker</title>
    <link rel="stylesheet" href="style.css">
</head>
<body>
    <div class="toolbar">
        <button onclick="startCreatingField()">+</button>
        <button onclick="finishCreatingField()">tick</button>
    </div>
    
    <svg xmlns="http://www.w3.org/2000/svg"
     viewBox="0 0 width height" id="garden-map" onload="makeDraggable(evt)">
    <script type="text/javascript"> //THIS IS WERE THE ERROR HAPPENS
    </script>
    <polygon class="draggable" fill="#ffa500" points="169 156 174 182 150 170 126 182 131 156 112 138 138 134 150 110 162 134 188 138"/> //JUST FOR TEST
</svg>
</body>
<script src="magic.js"></script>
</html>

【问题讨论】:

    标签: javascript svg


    【解决方案1】:

    magic.js 的加载是在浏览器遇到 makeDraggable 之后进行的。

    &lt;script&gt; 移动到&lt;head&gt;,使其首先加载。

    【讨论】:

      猜你喜欢
      • 2022-01-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-01-25
      • 1970-01-01
      • 2017-05-22
      相关资源
      最近更新 更多