【发布时间】: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