P粉9989207442023-08-22 16:18:05
Your best option here is to use a query string to "send" the value.
How to get the query string value using JavaScript
If this is more than just a learning exercise, you may want to consider the safety of doing this.
Global variables won't help you here as they will be destroyed once the page is reloaded.
P粉4457509422023-08-22 14:38:29
Without reading your code, only your scenario, I would use localStorage
to solve it.
Here's an example that I'll use prompt()
to simplify.
On page 1:
window.onload = function() { var getInput = prompt("嘿,在这里输入一些内容:"); localStorage.setItem("storageName",getInput); }
On page 2:
window.onload = alert(localStorage.getItem("storageName"));
You can also use cookies, but localStorage allows more space and does not send them back to the server when the page is requested.