[英]Javascript Pass value to another JS Class and HTML Page
I have two JavaScript
classes/files, and two html
pages: 我有两个
JavaScript
类/文件和两个html
页面:
-month.html
-month.js
-day.html
-day.js
I am trying to figure out how to pass a value from one html/js
to the other. 我试图弄清楚如何将值从一个
html/js
传递给另一个。 For instance, when a user clicks on a date in the month.html
, I would like to pass that value from month.js
to day.js
and then display it on the day.html
. 例如,当用户点击
month.html
的日期时,我想将该值从month.js
到day.js
,然后将其显示在day.html
。 Is there a quick way that I can just pass a date to the day.html and then work with it in day.js
? 有没有一种快速方法可以将日期传递给day.html,然后在
day.js
使用它?
Thanks! 谢谢!
I would suggest using a cookie or localStorage for this purpose. 我建议为此目的使用cookie或localStorage。
If using localStorage in month.js do: 如果在month.js中使用localStorage,请执行以下操作:
localStorage.setItem('date', date);
and in day.js retrieve the date with: 并在day.js中检索日期:
var date = localStorage.getItem('date');
Keep in mind, that localStorage is not supported in older browsers. 请记住,旧版浏览器不支持localStorage。 You can read more about alternative local storage methods here: http://diveintohtml5.info/storage.html
您可以在此处阅读有关替代本地存储方法的更多信息: http : //diveintohtml5.info/storage.html
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.