首页 > 解决方案 > 未捕获的类型错误:无法读取 null 的属性“getBBox”

问题描述

我试图复制这个codepen但是我得到了错误:

 tank.js:441 Uncaught TypeError: Cannot read property 'getBBox' of null
    at AnalogTank.calculateArrowPosition (tank.js:441)
    at AnalogTank.applyArrowAttribute (tank.js:408)
    at AnalogTank.addArrow (tank.js:404)
    at AnalogTank.initTower (tank.js:316)
    at AnalogTank.init (tank.js:126)
    at new AnalogTank (tank.js:113)
    at jQuery.fn.init.$.fn.analogTank (tank.js:105)
    at tank.js:1124

似乎 src="https://cdnjs.cloudflare.com/ajax/libs/d3/4.2.3/d3.js"> 中的 d3 版本可能是问题的一部分,但我不知道如何纠正错误。

这是我的HTML头供参考。

<!DOCTYPE HTML>


<html>
    <head>
        <meta charset="utf-8" />
        <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no" />
        <script src="https://cdnjs.cloudflare.com/ajax/libs/d3/4.2.3/d3.js"></script>
        <script src="https://code.jquery.com/jquery-3.1.0.js"></script>
        <script src="https://cdnjs.cloudflare.com/ajax/libs/jqueryui/1.12.1/jquery-ui.js"></script>
        <script type="text/javascript" src="tank.js"></script>

        <link rel="stylesheet" href="tank.css" />


    </head>

标签: javascriptd3.js

解决方案


在加载 HTML 之前,我不应该尝试加载我的 tank.js。我只是将 tank.js 的标签移到了文档的底部。


推荐阅读