我是JS新手,刚才对我的foll有怀疑。编码
getInput.js将变量传递给JS中的另一个页面
setVal(5,6);
global.js
var x ; var y ;
function setVal(a,b){
x=a;
y=b;
}
function getVal(){
//code to return the value of x and y as an array
}
getVal.js
arr = getVal();
1.HTML:
<html>
<head>
<script src='global.js'></script>
<script src='getInput.js'></script>
</head>
<body>
<!-- content of body -->
<!--Code to navigate to 2.html -->
</body>
</html>
2.HTML:
<html>
<head>
<script src='global.js'></script>
<script src='getVal.js'></script>
</head>
<body>
<!-- content of body -->
</body>
</html>
当2.HTML被重定向,它显示阵列“未定义”
我知道,变量可以使用页面缓存之间传递,并有各种其他方法来做同样的事情。但我想知道为什么上述方法不起作用。如果有人让我知道更好的解决方案,这将是相当可观的。