从一个javascript文件调用变量到另一个 [英] Call variables from one javascript file to another

查看:135
本文介绍了从一个javascript文件调用变量到另一个的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何从另一个javascript文件中调用我存储的变量?

How can I call the variables that I stored in one javascript file from another?

var.js

var VAR = new Object;
VAR.myvalue = "Yeah!";

然后我想在这里使用VAR.myvalue

then I want to use VAR.myvalue here

sample.js

sample.js

alert(VAR.myvalue);


推荐答案

首先,而不是

var VAR = new Object;
VAR.myvalue = "Yeah!";

选择

var VAR = {
    myvalue: "Yeah!"
 };

但只要 var.js 是引用第一个之前 sample.js,你所拥有的应该可以正常工作。

But so long as var.js is referenced first, before sample.js, what you have should work fine.

var.js将声明,并初始化VAR,它将从sample.js

var.js will declare, and initialize VAR, which will be read from the script declared in sample.js

这篇关于从一个javascript文件调用变量到另一个的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆