HTML 在文本区域保存文本

HTML save text in textarea

我有这个文本框

<textarea rows="20" cols="100"> </textarea>

当有人在其中输入文字并刷新页面时,我如何让输入的文字停留在那里

我会自己尝试一些事情,但我不知道从哪里开始...

您可以像这样使用 Jquery 和本地存储。见 fiddle https://jsfiddle.net/sxh0n7d1/13/

这将适用于多个 <textarea>

window.onbeforeunload = function() {
     $('textarea').each(function(){    
        var id = $(this).attr('id');
        var value = $(this).val();
       localStorage.setItem(id, value);
    }); 
}
window.onload = function() {        
    $('textarea').each(function(){    
       var id = $(this).attr('id');
       var text2 = localStorage.getItem(id);
       if (text2 !== null) $('#'+id).val(text2);
    }); 
}