简体   繁体   English

如何将 javascript 变量从一个 javaScript 文件传递到另一个 javascript 文件?

[英]how to pass javascript variables from one javaScript file to another javascript file?

I have two javascript files in one folder.I want to pass a variable one javascript file to another.what procedure should I use?我在一个文件夹中有两个 javascript 文件。我想将一个变量 javascript 文件传递给另一个文件。我应该使用什么程序?

window.postMessage is used for cross document messages. window.postMessage用于跨文档消息。 Use those messages to share data.使用这些消息来共享数据。

Question is bit confusing, If the 2 javascript files are in 2 different pages you can use a query string to pass the values.问题有点令人困惑,如果 2 个 javascript 文件位于 2 个不同的页面中,您可以使用查询字符串来传递值。

If both of them are in a single page the value can be simply passed using a variable.如果它们都在一个页面中,则可以使用变量简单地传递值。 Simply define the variable int he first called script file or in the page.只需在他首先调用的脚本文件或页面中定义变量 int。 It can be accessed from any other javascript in the page defined below the first script.它可以从第一个脚本下方定义的页面中的任何其他 javascript 访问。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM