javascript - 未捕获的类型错误:无法读取 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>
解决方案
在加载 HTML 之前,我不应该尝试加载我的 tank.js。我只是将 tank.js 的标签移到了文档的底部。
推荐阅读
- css - 选择元素文本的垂直居中
- xaml - Xamarin ControlTemplate 设置 BindingContext
- database - 使用 Join 和计算进行查询
- wordpress - 如何使用子主题更新 WordPress 主题文件
- javascript - 尝试使用 Gmail API 计算 Gmail 中使用的标签数量
- javascript - 如何使用 JS/JQuery 根据位置在另一个页面上重定向用户?
- git - 如何使用 git 合并到不相关的分支?
- javascript - JavaScript 中的回文
- ruby-on-rails - 在 Rails 中将 pdf 上传到亚马逊
- spring - 如果在数据库事务之后的方法中发生异常,则在 Spring 中回滚事务