gpt4 book ai didi

javascript - 来自另一个文件的变量

转载 作者:行者123 更新时间:2023-12-03 11:08:26 27 4
gpt4 key购买 nike

我有 data.js 文件,内容如下:

var table=[];
table.push('10','11');

我想在其他脚本中使用它,如下所示:

var script=document.createElement("script");
script.src="http://xxxx/data.js";
document.body.appendChild(script);

setTimeout(function(){alert(table);},5000);

当我将其粘贴到 Firebug 并运行它时,我第一次得到了

function () {
[native code]
}

当我再次运行这个时,我得到了我想要的:

10,11

如何在第一次运行此脚本时获得此结果?

最佳答案

Firebug 有一个名为 table 的函数,以表格布局呈现数据,以便轻松检查对象。尝试去 firebug 并做

table("a");

然后

table({a:1,b:2});

这就是您获得 native 函数的原因

关于javascript - 来自另一个文件的变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27721881/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com