gpt4 book ai didi

javascript - 如何使用 javascript 将值从一个 html 页面传递到另一个 html 页面

转载 作者:太空狗 更新时间:2023-10-29 15:38:26 24 4
gpt4 key购买 nike

在第一页中,我在文本框中获取值,我需要将其传递到另一个页面,该页面分为 2 个框架。我需要在第一帧的 html 页面中显示该值。请给我一个简单的例子。我试过window.document.getElementById("inputbox1").value但我无法获得值(value)。

请给我一个简单的例子。

最佳答案

我会使用 localStorage,正如@MicrosoftGoogle 建议的那样,但目前还没有得到很好的支持,您可以使用纯 javascript 来实现这一点。你的表单页面上会有这样的东西:

<form action="param-received.html" method="GET">
<input type="text" id="foo" name="foo">
<input type="submit" value="Send" name="submit" id="submit">
</form>

点击“发送”按钮后,您将被重定向到 /param-received.html?foo=hola&submit=Send

  • location.search 属性包含参数链。
  • >?连接 URL 和参数字符串。
  • & 分隔多个参数。
  • = 为变量赋值。

下面是处理在 param-received.html 上发送的数据的完整代码:

<script language="JavaScript">
function processForm()
{
var parameters = location.search.substring(1).split("&");
var temp = parameters[0].split("=");
l = unescape(temp[1]);
alert(l); //Dialog with the text you put on the textbox
}
processForm();
</script>

关于javascript - 如何使用 javascript 将值从一个 html 页面传递到另一个 html 页面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13470285/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com