简体   繁体   English

在HTML页面之间传递变量值

[英]passing variable values between HTML pages

I created this HTML calendar, when the user selects a date, JS returns a value like this: 我创建了这个HTML日历,当用户选择一个日期时,JS返回的值是这样的:

<li class ="num" id="day6" onclick = "return checkDate(6)"> </li>

I called the value in my external JS file: 我在外部JS文件中调用了该值:

function checkDate(a) {
    a = dayNum;
    alert(dayNum);
    day = dayNum- start_day2; }

The alert works, but when I try to load this same script on another page, it alerts "undefined". 该警报有效,但是当我尝试在另一个页面上加载相同的脚本时,它会发出“未定义”警报。 I assume it's because of the reloading the value for a is not set. 我认为这是因为重新加载未设置a的值。 Is there a way around this? 有没有解决的办法? Sticking to Javascript only please because that's the only Language I know fairly well. 请只使用Java语言,因为那是我相当了解的唯一语言。

Thanks. 谢谢。

function checkDate(a) {
    var dayNum, day, start_day2;
    dayNum = a;
    start_day2 = null; //no value specified in given code
    alert(dayNum);
    day = dayNum- start_day2; 
}

Short cut to what you've shown 捷径显示

function checkDate(a) {
    alert(a);
}

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

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