简体   繁体   English

Javascript将值传递给另一个JS类和HTML页面

[英]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.jsday.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.

相关问题 如何在JavaScript中将值从一个html页面传递到另一个页面? - How to pass value from one html page to another in JavaScript? javascript将值传递给另一个页面 - javascript pass value to another page 如何将 javascript 变量值从一个 html 页面传递到另一个 html 页面? - How to pass the javascript variable value from one html page to the another html page? 如何将参数从一个页面 function 传递到另一个页面 class function 在 Z9E13B69D1D715A927102ACAAAF14Z - how to pass parameter from one page function to another page class function in Javascript / Node js 如何在javascript中传递一个值并在另一个页面上获取它? - how to pass a value in javascript and get it on another page? 如何使用JavaScript重定向将值传递给HTML页面? - How to pass a value to the HTML page with JavaScript redirection? 将boolean类型js变量值从一个html页面传递到另一个 - pass boolean type js variable value from one html page to another 如何将值从一个页面javascript传递到另一页面javascript - how to pass the value one page javascript to another page javascript 如何使用JavaScript将值从一个HTML页面传递到另一个HTML页面? - How can I pass a value from one HTML page to another using JavaScript? 如何使用javascript将值从父窗口传递到另一个html页面? - How to pass a value from a parent window to another html page using javascript?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM