【发布时间】:2019-06-18 08:40:52
【问题描述】:
我在主页上使用 HTML 和 JS 将变量发送到另一个 js 页面。
我这样做了 在页面索引中,我使用 index.js 创建按钮
<a href="index.html" id= "button1">Easy</a>
在 index .js 中我做了这个
window.addEventListener('load', function(){
document.getElementById("button1").onclick = function(){
sessionStorage.setItem("mood", '1');
window.location.replace("second.html");
};
在 second.js 中,我在 js 中这样做是为了获取情绪变量。
data = sessionStorage.getItem('mood');
在 Firefox 上一切正常(在本地),但是当使用 Chrome o 在线上传时,按钮不起作用,因为它不会重定向到 second.html
有人可以帮助我吗? p.s 我不想使用脚本(Ajax、Jquery 等)
【问题讨论】:
-
button1 是指进入 second.html 还是 index.html?
-
button1 调用 index.html 有 index.js 替换为 second.html
-
但是你的 button1 href = "index.html" 但是在 onclick 你希望它转到 "second.html"?
-
是的,变量。但我不能做“href =second.html”,因为不要调用 index.js onclick 方法,也不要设置变量 mood @Jaxi
-
酷。我会写一个快速的答案,以便可以接受,否则问题将被保留为“未回答”
标签: javascript html session button interaction