2017-08-15 54 views
-1

每当我尝试访问铬开发人员工具中的对象,我看到错误波纹管: VM4939:1未捕获TypeError:无法读取未定义 的属性“单元格”:1 :13在铬开发工具中的对象访问不起作用

我的代码是:

<head> 
    <script> 
    var new_2ELayout; 
    function doOnLoad() { 
     var new_1CLayout = new dhtmlXLayoutObject({ 
     parent: document.body, 
     pattern: "1C" 
     }); 
     var new_1CLayoutA = new_1CLayout.cells("a"); 
    </script> 
</head> 
+2

该代码在语法上不正确;你在某处丢失了一个'}'。 – Pointy

+0

看起来你只是错过了你的功能的大括号。 –

回答

0

你在我看来,有2种方式来做到这一点:

1 - 申报外功能 var new_2ELayout, new_1CLayout;

2变量 - 声明全局变量

但最好的所有选项都是第一个。

+0

不是我嫉妒,但为什么这被选为接受的答案,而不是我的?我说同样的事情,我提供了有效更正的有效代码示例。 –

3

这是因为new_1CLayoutdoOnLoad()函数中定义的,所以I'T不能从外部访问。在外面宣布。

var new_2ELayout, new_1CLayout; 

function doOnLoad() { 
     new_1CLayout = new dhtmlXLayoutObject({ 
      parent: document.body, 
      pattern: "1C" 
     }); 

     var new_1CLayoutA = new_1CLayout.cells("a"); 

} // and don't forget to close the function here 

// Now you can log new_1CLayout outside the function