try{ localStorage.setItem(key,value); }catch(oException){ if(oException.name == 'QuotaExceededError'){ console.log('超出本地存储限额!'); //如果历史信息不重要了,可清空后再设置 localStorage.clear(); localStorage.setItem(key,value); } }
localStorageService.get(key);
localStorageService.clearAll();
localStorageService.clearAll(/^\d+$/);
localStorageService.remove(key1, key2, key3);
https://lzw.me/a/html5-localstorage.html
var re = /ab+c/;
正则表达式字面量在脚本加载后编译。若你的正则表达式是常量,使用这种方式可以获得更好的性能。
调用RegExp
对象的构造函数,如下所示:
var re = new RegExp("ab+c");