我正在使用 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/