【问题标题】:Display Post value from HTML form to another HTML form从 HTML 表单显示 Post 值到另一个 HTML 表单
【发布时间】:2015-05-16 16:58:29
【问题描述】:

快速提问。我开始学习本地存储 HTML5。如何从表单中获取值并将该值显示在另一个 HTML 表单页面上? 例如,我这里有两种形式。 如果我填写表格 1 并单击提交按钮,则该值将在表格 2 上显示为只读。

我在下面尝试过:

HTML 表格 1:

<html>
<head>
<title>Save Value</title>
<script type="text/javascript"> 
function saveVal() {
    var inputFirst = document.getElementById("name").value;
    localStorage.setItem("name", inputFirst);
    inputFirst = localStorage.getItem("name");
}

</script>
</head>
<body>
<form action="display.html" method="get">
<label> 
First Name:
<input name="name" size="20" maxlength="25" type="text" id="name" />
</label>

<input type="submit" value="submit" onclick="saveVal()"/>
</form>
</body>
</html>

HTML 表格 2:

<html>
<head>
<title>Display</title>
<script type="text/javascript">
function result() {
    var storedVal = document.getElementById("name");
    storedVal.value = localStorage.getItem("name");
}
</script>
</head>

<body>
<form action="#">
<label>
First Name:
<input name="name" size="20" maxlength="25" type="text" id="name" readonly="readonly" />
</label>
</form>
</body>
</html>

【问题讨论】:

  • 在 display.html 中你没有调用函数 result(),

标签: javascript html


【解决方案1】:

display.html 中你没有调用函数 result(),

试试这个,

<html>
<head>
<title>Display</title>
</head>
<body>
<form action="#">
<label>
First Name:
<input name="name" size="20" maxlength="25" type="text" id="name" readonly="readonly" />
</label>
<script type="text/javascript">
 var storedVal = document.getElementById("name");
    storedVal.value = localStorage.getItem("name");
</script>
</form>
</body>
</html>

【讨论】:

    猜你喜欢
    • 2013-08-18
    • 1970-01-01
    • 1970-01-01
    • 2021-06-29
    • 2016-10-11
    • 2019-07-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多