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

use*_*788 5 html javascript

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

请给我一个简单的例子.

Tom*_*duy 9

我会选择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>
Run Code Online (Sandbox Code Playgroud)

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

  • location.search attribute包含参数链.
  • ?连接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>
Run Code Online (Sandbox Code Playgroud)


kir*_*nvj 0

将值写入 cookie 并从其他页面读取 cookie。

如需写入和读取 cookie,请查看此处