0
localStorage
에 문제가있어서 값을 저장하려고 시도하고 있습니다. localStorage
값이 없으면 First Try
이됩니다.localStorage에 텍스트 상자 값을 올바르게 저장하는 방법은 무엇입니까?
자바 스크립트 :이
// 1. onload - Fill the textbox named "myData" with data from local storage variable called
// 'myData'. If no local storage is available, fill the textbox with the words "First Try". If there is a value then, keep it. So, when the page refreshes it will still be there in the textbox.
function loadIt() {
var myData = document.getElementById("myData");
// place content from previous edit
if (!myData.value)
{
myData.value = window.localStorage.getItem('value');
}
// your content will be saved locally
window.localStorage.setItem('value', myData.value);
HTML : 로컬 스토리지를 읽고 텍스트 상자에서 설정해야 onload
이벤트에서
<input type="text" id="myData" value=""/>