【发布时间】:2012-03-16 06:52:37
【问题描述】:
我真的很震惊。实际上问题是,我有 2 个网页名称为 menu.html 和 index.html。在 menu.html 中,我有 3 个按钮,例如“一、二、三”,当我单击任何一个按钮时,它都会重定向到 index.html。所以,我编写了一个 common.js 文件来获取我在 menu.html 中单击的按钮的值。我已将 common.js 包含在 menu.html 和 index.html 中。
common.js:
var text=" ";
$(document).ready(function() {
$('input:button').click(function() {
text = $(this).val();
alert(text); //here am getting correct values for a button like 'one,two or three' in menu.html page
});
});
现在我需要在 index.html 中的 another.js 文件中获取“text”的值。
另一个.js:
$(document).ready(function() {
alert("text "+text); //here am getting empty value.
});
此外,我正确地包含在 index.html 中:
<script src="common.js" type="text/javascript"></script>
<script src="another.js" type="text/javascript"></script>
这里做错了什么?提前谢谢你。
【问题讨论】: