如何使用javascript将值从一个html页面传递到另一个html页面?
我试图将值从一个html页面传递到另一个html页面,但我遇到了一些错误 下面是我的html第1页代码:如何使用javascript将值从一个html页面传递到另一个html页面?,javascript,html,Javascript,Html,我试图将值从一个html页面传递到另一个html页面,但我遇到了一些错误 下面是我的html第1页代码: <!DOCTYPE html> <html> <head> <script type="text/javascript"> function first() { location.href = "onclick2.html"; } </script&g
<!DOCTYPE html>
<html>
<head>
<script type="text/javascript">
function first() {
location.href = "onclick2.html";
}
</script>
</head>
<body>
<button onclick="first()" >Home</button>
<form action="onclick2.html" method="post">
<input type="text" name="sender" />
<input type="submit" value="send"/>
</form>
</body>
</html>
函数优先(){
location.href=“onclick2.html”;
}
家
下面是我的html第2页代码
<!DOCTYPE html>
<html>
<head>
<script type="text/javascript">
function first() {
location.href = "onclick.html";
}
</script>
</head>
<body>
<button onclick="first()">Home2</button>
<form action="onclick.html" method="get">
<input type="text" name="reciver" />
</body>
函数优先(){
location.href=“onclick.html”;
}
家庭2
您可以在url中传递值并按如下所示进行传输:
location.href = "http://www.domainname.com/login.html?FirstName=admin&LastName=admin"
你的错误是什么?我完全不明白你想做什么。你能详细解释一下吗?值不会从一个页面传递到另一个页面……传递表单内容的唯一方法是在表单中使用
method=“get”
,然后在第二个页面的JS代码中,通过解析文档来读取参数。位置
,即在?
处拆分参数,然后在&
处再次拆分参数。另一种方法是将字段存储在本地存储器中,然后在第2页上读取。必须使用这些变通方法的原因是,表单内容通常由服务器端脚本处理,而不是JavaScript。