![](/img/trans.png)
[英]How to get data from form to javascript and redirect to another page?
[英]How to get data from a form in another page (JavaScript)
我的英语不够好,所以希望您能理解我的问题...
我有一个带有表单的页面“ A”。 当我单击“提交”时,我希望它打开/重定向到页面“ B”,并且要在页面“ B”上显示页面“ A”中的表单数据...我想使用JavaScript来做到这一点,不在jQuery左右。 我尝试使用window.opener
或类似的东西...接下来,显示示例代码。
页面“ A”:
<html>
<head>
</head>
<body>
<form method="post" name="form1" id="form1">
<input type="text" name="field1">
<input type="submit" name="submit" onclick="window.open('show.html');">
</form>
</body>
</html>
页面“ B”:
<html>
<head>
</head>
<body>
<script>
var x = opener.document.forms["form1"]["field1"].value;
document.write(x);
</script>
</body>
</html>
页面“ B”可以显示页面“ A”上的数据非常重要。 我不能使用PHP或其他技术...:/
我希望你能理解我的要求。 谢谢!
**更新
正如Sagar Hani指出的,解决方案(至少对我而言)是localStorage。 无论如何,感谢回答的人!
以下是您想要的确切解决方案。
页面“ A”(a.html)
<html>
<head>
</head>
<body>
<form action="b.html" method="get" name="form1" id="form1">
<input type="text" name="field1">
<input type="submit" name="submit">
</form>
</body>
</html>
页面“ B”(b.html)
<script>
alert(findGetParameter("field1"))
function findGetParameter(parameterName) {
var result = null,
tmp = [];
location.search
.substr(1)
.split("&")
.forEach(function (item) {
tmp = item.split("=");
if (tmp[0] === parameterName) result = decodeURIComponent(tmp[1]);
});
return result;
}
</script>
不能是PHP吗? 使用PHP,您还可以将信息发送到页面B并向用户显示所有信息。 实际上,由于它是服务器端的过程,因此对用户更友好。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.