在有参数的页面将想要传递的参数设置进去
window.localStorage.setItem('username', user.username);
当跳转页面时,就会直接把这个参数传递过去,俩个页面共享
window.location.href='personal_center.html'
在接收参数的页面用如下接收
window.localStorage.getItem('username')
这篇博客介绍了如何利用JavaScript的window.localStorage对象在不同页面之间传递参数。通过设置localStorage的键值对,如`window.localStorage.setItem('username', user.username)`,可以在跳转到`personal_center.html`时将参数保留。在目标页面,可以使用`window.localStorage.getItem('username')`来获取并使用这些参数。这种方法对于实现页面间的数据共享非常实用。
在有参数的页面将想要传递的参数设置进去
window.localStorage.setItem('username', user.username);
当跳转页面时,就会直接把这个参数传递过去,俩个页面共享
window.location.href='personal_center.html'
在接收参数的页面用如下接收
window.localStorage.getItem('username')
536

被折叠的 条评论
为什么被折叠?