나는 localStorage
개체에 대해 약간 혼란 스럽다. localStorage
은 분명히 일반적인 객체처럼 속성을 만들고 메서드를 만들 수 있다는 것을 의미합니다.localStorage 메서드를 만드는 방법
localStorage
안에 메서드를 만드는 방법을 알아 내려고하고 있습니다. 이다 내가 현재 가지고있는 :
localStorage = {
firstname: function(){
//get the firsname from the input and set it as the localstorage firsname
$("#sublog").bind("click", function(){
$("input[name='fName']").val();
});
},
lastname: function(){
//get the lastname from the input and set it as the localStorage lastname
$("#sublog").bind("click", function(){
$("input[name='lName']").val();
});
}
};
내 HTML은 다음과 같습니다 : 클라이언트가 삽입 할 때
<div id="log">
<form>
<input type="text" id="fName" name="fName" placeholder="FirstName" />
<input type="text" id="lName" name="lName" placeholder="LastName" />
<input type="submit" id="sublog" name="login" value="Login" />
</form>
는 분명히, 나는 단순히 localStorage.firstname
및 localStorage.lastname
로 클라이언트의 이름을 저장할 수 있도록하기 위해 자신의 이름과 성을 저장하십시오.
좋아요. 그런 변수를 설정할 수 없습니다. var firstname = (입력 값); var lastname = (입력 값) 다음과 같이 localStorage에 설정하십시오. localStorage = {first : firstname, last : lsatname}; ? –
@ בועזהוך 업데이트 된 답변 확인 – krishgopinath