Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/75.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/search/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何修复此本地存储HTML5错误?_Html_Textarea_Local Storage - Fatal编程技术网

如何修复此本地存储HTML5错误?

如何修复此本地存储HTML5错误?,html,textarea,local-storage,Html,Textarea,Local Storage,我不知道我做错了什么。单击“保存”按钮时,应该将文本从文本区域发送到本地存储器。然后,当您关闭并重新打开页面时,保存的文本应该会返回。但是当我关闭文档并再次打开它时,它是空白的。是否存在我忽略的错误,或者是否应尝试其他方法保存到本地存储 <script> function save () { var inputvalue = document.getElementById('textfield').value; localstorage.setItem('text',

我不知道我做错了什么。单击“保存”按钮时,应该将文本从文本区域发送到本地存储器。然后,当您关闭并重新打开页面时,保存的文本应该会返回。但是当我关闭文档并再次打开它时,它是空白的。是否存在我忽略的错误,或者是否应尝试其他方法保存到本地存储

<script>
function save () {
    var inputvalue = document.getElementById('textfield').value;
    localstorage.setItem('text', inputvalue);
}

function load() {
    var storedValue = localStorage.getItem('text');
    if(storedValue) {
        document.getElementById('textfield').value = storedValue;
    }
}
</script>
</head>

<body onload="load()">
 <textarea id="textfield">
 </textarea>
 <input type="button" value="Save" onclick="save()" />
</body>

函数保存(){
var inputvalue=document.getElementById('textfield').value;
setItem('text',inputvalue);
}
函数加载(){
var storedValue=localStorage.getItem('text');
if(存储值){
document.getElementById('textfield')。value=storedValue;
}
}

您是第一次给出save吗?您刚刚关闭了选项卡还是结束了浏览器会话?如果结束浏览器会话,
localStorage
将被清除。可能存在重复的