且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何将变量从一个脚本传递到另一个脚本

更新时间:2023-01-08 09:43:13

两个人< script> 块共享相同的执行范围,全局范围。您在一个< script> 中的全局范围内创建的所有变量都可以在另一个中访问。

Two individual <script> blocks share the same execution scope, the global scope. All variables you create in the global scope inside one <script> are accessible in the other.

<script>
    var a = 5;
</script>

<script>
    alert( a );
</script>

同样适用于函数。

<script>
    var b = function( c ){ return c; }
</script>

<script>
    alert( b(12) );
</script>

你可以排除,你的问题似乎存在于第一个脚本中,这不是语法上的有效。

That you can rule-out, your problem seems to lay in the first script, which is not syntactically valid.