localstorage、stopPropagation、preventDefault、tap
需要学习的知识:
- localstorage
var storage = window.localStorage;
//存储数据的方法就是直接给window.localStorage添加一个属性
storage.key = value;
storage[key]=value;
storage.setItem("key","value");
storage.getItem("key");
var value = storage.key
//清除localstorage
清除键值对使用removeItem()
全部清除使用clear();
//将json格式保存到本地
目前javascript使用非常多的json格式,如果希望存储在本地,可以直接调用JSON.stringify()将其转为字符串。读取出来后调用JSON.parse()将字符串转为json格式,如下所示:
var details = {author:"isaac","description":"fresheggs","rating":100};
storage.setItem("details",JSON.stringify(details));
details = JSON.parse(storage.getItem("details"));
- stopPropagation
- preventDefault
- tap