我对这个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
姓氏以保存它们的时间。