【问题标题】:cannot read property 'insertBefore' of null - handsontable.full.js:3714无法读取 null 的属性“insertBefore”-handsontable.full.js:3714
【发布时间】:2015-10-25 03:34:30
【问题描述】:

我尝试运行快速启动链接 (Quick Start) 中提到的示例。通过 Git 中心下载所有文件。尝试运行快速入门中提到的示例时,出现以下错误“无法读取 null 的属性 'insertBefore' - handsontable.full.js:3714”。请帮我运行基本示例。

使用的版本 - v0.16.1

代码:

<!DOCTYPE html>
<html>
<head>
     <script src="dist/handsontable.full.js"></script>
     <link rel="stylesheet" media="screen" href="dist/handsontable.full.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>

<script>
    var data = [
    ["", "Ford", "Volvo", "Toyota", "Honda"],
    ["2014", 10, 11, 12, 13],
    ["2015", 20, 11, 14, 13],
    ["2016", 30, 15, 12, 13]
    ];

  var container = document.getElementById('example');
  var hot = new Handsontable(container, {
            data: data,
            minSpareRows: 1,
            rowHeaders: true,
            colHeaders: true,
            contextMenu: true
          });

</script>
<style>
body {
background-color: white;
margin: 20px;
}

h2 {
  margin: 20px 0;
}
</style>
</head>

 <body>


    <h2>Default Handsontable Demo</h2>

     <div id="example"></div>

 </body>

【问题讨论】:

标签: javascript html handsontable


【解决方案1】:

尝试将 3 个脚本节点放在身体而不是头部。感觉像是你如何加载模块的问题。

【讨论】:

    【解决方案2】:

    我遇到了同样的错误,至少对我来说,发生错误是因为我使用了一个不存在的元素 ID。

    在这一行:

    var container = document.getElementById("example");
    

    确保您的 div 的 ID 具有相同的名称。在这种情况下,它是“示例”:

    <div id="example"></div>
    

    如果加载Handsontable时容器为undefined,则会显示此错误信息。

    【讨论】:

      【解决方案3】:

      有时甚至空间会导致此错误。

      // example 
      var container = document.querySelector('header .container');
      //in this i made mistake of space between header and container class so  he can't find and show me error
      var container = document.querySelector('header .container');
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2021-09-25
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多