日期:2014-05-17 浏览次数:20703 次
var saveKeyValue = function(key, value) { if (typeof localStorage !== undefined) { try { localStorage.setItem(key, value); } catch (e) { if (e == QUOTA_EXCEEDED_ERR) { alert('Quota exceeded'); } } } }; var getValueByKey = function(key) { var value = localStorage.getItem(key); return value == null ? 'empty!' : value; }; var removeKey = function(key) { localStorage.removeItem(key); }; saveKeyValue('name', 'Jobs'); alert(getValueByKey('name')); removeKey('name'); alert(getValueByKey('name'));