1 回答
TA贡献1830条经验 获得超9个赞
有多种方法可以做到这一点。
使用查询参数
使用数据(本地存储,会话存储)
// 使用本地存储
// Page 1
$('#load1').click(function(){
localStorage.setItem("username", "some name")
});
// page 2
$(function() {
// get data
const username = localStorage.getItem("username")
})
使用查询参数
// If data is small, can use query params
// Page 1
$('#load1').click(function(){
// redirect here with query param
window.location = "/page2.html" + "?usename=" + "some name"
});
// Page 2
$(function() {
// get data
const username = localStorage.getItem("username")
// simply get query param, can write logic and see other code to get param
const username = window.location.split("?usename=")[1]
})
添加回答
举报
