使用单击函数javascript将参数传递给另一个html页面
我有一个页面page1.html,并使用重定向功能将其重定向到另一个页面page2.html: 第1页使用单击函数javascript将参数传递给另一个html页面,javascript,html,Javascript,Html,我有一个页面page1.html,并使用重定向功能将其重定向到另一个页面page2.html: 第1页 。。。 ... 函数重定向1(参数1){ $('#link1')[0]。单击(函数(){ }); } ... 第2页 。。。 ... 我想做的是将argument1传递给page2,并将其分配给input test2 value。 我找不到这两个页面之间的连接,因为重定向页面时链接已断开。有什么想法吗?有多种方法 使用查询参数 使用数据(本地存储、会话存储) //使用本地存储 // Pa
。。。
...
函数重定向1(参数1){
$('#link1')[0]。单击(函数(){
});
}
...
第2页
。。。
...
我想做的是将argument1传递给page2,并将其分配给input test2 value。
我找不到这两个页面之间的连接,因为重定向页面时链接已断开。有什么想法吗?有多种方法
// 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]
})
尝试使用localStorage或history stack/LocationHash当然,原始文件不是这样的,为了清晰起见,我修改了它们。你能给第一个举个例子吗?很快就会更新的。!sessionStorage.setItem(“lastname”、“Smith”);会更好的,是的!视情况而定,如果您需要数据,则应在会话中清除。
// 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]
})