小小插件,封装了一个存取删
<script type="text/javascript"> /* *getItem(name) * *setItem(name,value) * *remove(name) * */ var optionStorage = { getObject:function(name){ if(name){ return JSON.parse(locaStorage.getItem(name)); }else{ return null; } }, getItem:function(name){ if(name){ return JSON.parse(locaStorage.getItem(name)); }else{ return null; } }, setItem:function(name,value){ if(name){ return JSON.parse(locaStorage.getItem(name,value)); } }, setObject:function(name,value){ if(name){ var options = this.getObject(name)||{}; for (var tempName in value) { options[tempName] = value[tempName]; } locaStorage.steItem(name,JSON.stringifg(options)); } }, remove:function(name){ if(name){ localStorage.removeItem(name); } } } </script>