在 JavaScript 中使用输入"type=text"元素将值从一个页面传递到另一个页面



页面名称3.html

<html>
<body>
<form action="4.html" onSubmit="cal()">
<table>
<tr>
<td><input type="text" id="sen"/></td>
<td><input type="submit" value="tap me"/></td>
</tr>
</table>
</form>
</body>
<script>
function call(){
var a = document.getElementById("sen").value;
localStorage.setItem("a",a);
}
</script>
</html>

页面名称4.html

<html>
<body>
<table>
<tr>
<td><p id="r"></p></td>
</tr>
</table>
</body>
<script>
var get = localStorage.getItem('sen');
alert(get);
document.getElementById("r").innerHTML=get;
</script>
</html>

我正试图从3.html传递值到4.html,但它正在传递空值。为什么要传递空值?如何解决此错误?

在调用函数时出现错误onSubmit =,卡尔()">

定义的函数名是call()

除了你正在尝试用密钥a设置会话并检索键seen.

最新更新