Chrome 开发器工具中的对象访问不起作用



每当我尝试在chrome开发人员工具中访问对象时,我都会看到以下错误: VM4939:1 未捕获的类型错误:无法读取未定义的属性"单元格" 在 :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>

那是因为new_1CLayout是在doOnLoad()函数内部定义的,所以我不能从外部访问。在外面宣布。

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

在我看来,您有两种方法可以做到这一点:

1 - 声明函数外部的变量var new_2ELayout, new_1CLayout;

2 - 声明全局变量

但最好的选择是第一个。

最新更新