简体   繁体   English

在不同的 .js 文件之间传递变量; 在同一个 html 文件中

[英]Pass variables between different .js files; inside the same html file

can anyone help me to pass variables from one .js file to another one, the two .js are instantiated in the same html as following:任何人都可以帮助我将变量从一个 .js 文件传递​​到另一个文件,这两个 .js 在同一个 html 中实例化,如下所示:

<script src="file_1.js"></script>

<script src="file_2.js"></script>

the content of "file_1.js" is like this: “file_1.js”的内容是这样的:

var paragraph = readFile('file_to_read.tcl'); 

so what i need, is to use the "paragraph " variable in side the "file_2.js script所以我需要的是在“file_2.js 脚本”旁边使用“段落”变量

Great thanks in advance非常感谢提前

You can save them locally like this:您可以像这样将它们保存在本地:
file_1.js:文件_1.js:

window.paragraph = readFile('file_to_read.tcl'); 

file_2.js: file_2.js:

setTimeout(function(){ //a small timeout to let the variable be declared...
  alert(window.paragraph);
}, 100);

Codepen代码笔

暂无
暂无

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

相关问题 在不同的.js文件之间传递变量; 一个在iframe内 - Pass variables between different .js files; one is inside an iframe 如何在不同的JS文件之间共享相同的作用域变量 - How to share same scope variables between different JS files select 元素来自链接到同一个 js 文件的不同 html 文件 - select elements from different html files linked to the same js file 同一HTML中有2个不同的js文件 - 2 different js file in same html 我需要在.js文件,.html和.css文件之间传递的变量。 我该怎么做呢? - I need variables to pass between a .js file, an .html and a .css file. How do I do this? JS HTML CSS: how to make a function dynamically repeat with different variables each time while not repeating the same variables inside de function - JS HTML CSS: how to make a function dynamically repeat with different variables each time while not repeating the same variables inside de function 需要在同一HTML页面调用的两个不同JS文件中的两个$(document).ready函数之间确定优先级 - Need to prioritize between two $(document).ready functions in two different JS files being called by the same HTML page JavaScript - 如何在.js文件之间传递全局变量? - JavaScript - How can you pass global variables between .js files? 尝试在2个HTML文件之间共享的JS文件内部使用全局数组,但失败 - Attempting to use a global array inside of a JS file shared between 2 HTML files and failing 如何隔离同一组件的不同实例之间的js变量? - How to isolate js variables between different instances of the same component?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM