Javascript Handsontable - 未捕获的类型错误 : Cannot read property 'insertBefore' of undefined

标签 javascript handsontable

我正在使用 handsontable 库来创建整洁的表格。
我从字面上复制了教程,但控制台(Web 开发人员控制台)给了我以下错误:

Uncaught TypeError: Cannot read property 'insertBefore' of undefined            
handsontable.full.js:4471 

我在 <head> 中正确链接了 .css 和 .js 文件标签。

我的 javascript 看起来像这样:

var data = [
    ["", "Ford", "Volvo", "Toyota", "Honda"],
    ["2016", 10, 11, 12, 13],
    ["2017", 20, 11, 14, 13],
    ["2018", 30, 15, 12, 13]
];

var container = document.getElementById('temp');
var hot = new Handsontable(container, {
    data: data,
    rowHeaders: true,
    colHeaders: true,
    dropdownMenu: true
});

HTML:

<div id="temp"></div>

handsontable.full.js 中的第 4471 行是

rootElement.insertBefore(this.container, rootElement.firstChild);

表格没有显示,控制台的错误就是我得到的。

最佳答案

看起来像你的

document.getElementById('temp');

返回未定义的。

确保 Handsontable 构建时容器元素仍然存在。

关于Javascript Handsontable - 未捕获的类型错误 : Cannot read property 'insertBefore' of undefined,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36624007/

相关文章:

JavaScript 单击图像按钮

angular - Handsontable numbro 库中出现错误,仅在生产版本中发生

handsontable - 从javascript隐藏handsontable的列

javascript - 使用 Handsontable 获取行号

javascript - apply() 不适用于 Node.js eventemitter 的 emit() 函数

JavaScript 全局数组在 jQuery get 函数之外失去值

javascript - 如何使用 jquery 应用多个 css 图像过滤器

javascript - 如何从 javascript 运行 php 脚本

javascript - HandsOnTable - 显示单元格的工具提示

jquery - 如何禁用在handsontable中添加新行/列?