2016-04-14 113 views
1

我正在使用handsontable库来创建整洁的表。
我简直复制的教程,但控制台(web开发者控制台)给了我以下错误:Javascript Handsontable - 未捕获TypeError:无法读取undefined属性'insertBefore'

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

我都联系起来了的.css和.js文件在<head>标签文件正确。

我的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); 

不显示表中,控制台中的错误是我所拥有的。

+0

我的猜测是你正试图在页面存在之前阅读元素。要么调用onload代码,要么将代码放在页面上的元素后面。 – epascarello

回答

2

它看起来像你的

document.getElementById('temp'); 

返回undefined。

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

+0

你说得对。我正在动态加载我的内容,并且在加载内容之前调用脚本,因此div不存在。 – Dubb

0

您的rootElement参考是未定义的。请检查此变量的定义和分配的内容。

相关问题