html - 为什么我的 HTML 5 本地存储无法工作?

标签 html local-storage

我创建了一个简单的 html 页面来测试本地存储,但在我的一生中,我无法让它工作,即使我的 Firebug 显示本地存储存储的值,因为我在这里存储的值是我的代码第一个 html 页面名为 Testhtml.html

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>TEsthtml.html</title>
</head>

<script >
function save()
{
var passvalue = document.getElementById('entry_1').value;
localStorage.setItem('passingvalue', passvalue);
}
</script>

<body>

<form action="simple.html"  method="POST">
<label  for="entry_0">Type ur name</label>
<input type="text" name="entry.0.single" value=""  id="entry_0">
<br> 
<label  for="entry_1">ur pets name
</label>
<label  for="entry_1">type something</label>
<input type="text" name="entry.1.single" value=""  id="entry_1">
<br>
<input type="submit" name="submit" id="submit" onClick="save()" value="Submit">
</form>
</body>
</html>

第二种形式称为simple.html代码如下

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Simple HTML</title>
<script >
function load()
{
var storedvalue = localstorage.getItem('passingvalue');
if(storedvalue)
{
document.getElementById('tb1').value=storedValue;
}
}
</script>
</head>

<body onload="load()" >

<input id="tb1" name="tb1" type="text"/>
<input type="submit" name="submit" id="submit" onClick="load()" value="Submit">

</body>
</html>

我尝试在 simple.html 中运行此代码,这是唯一文本框中的第二种形式,它没有显示任何内容..尝试了很多不同的事情!!

最佳答案

这只是 Simple.html 第 8 行和第 9 行的打印错误; “localstorage”应为“localStorage”,“storedvalue”应为“storedValue”。

您应该查看浏览器的错误报告和开发人员工具,它们会帮助您自行解决此问题。我个人更喜欢在 Google Chrome 上进行开发,因为它的调试工具快速、简单且易于使用(如果您使用 Chrome,只需按 Ctrl+Shift+J)。

关于html - 为什么我的 HTML 5 本地存储无法工作?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8617520/

相关文章:

javascript - 零宽度空间使 HTML 链接无法点击

html - 如何将文本对齐到 flex-basis 元素的底部?

html - 使用 CSS 对 div 进行右对齐

javascript - HTML5 checkValidity 和不可见字段

google-chrome-extension - 从 localStorage 迁移到 chrome.storage

jquery - 单击响应菜单后效果过渡更平滑

php - 我如何在 PHP 旁边使用 HTML5 本地存储,将其用于 php session ,并存储 php 使用的其他信息

ReactJs保留多个react值并且刷新后不重置状态

javascript - 为什么 Electron 应用程序从开发工具访问时没有 localStorage 对象? (Ctrl-Shift-I)

javascript - Angular 1 : Last checkbox doesn't stay checked after page refresh