我使用 PersistJS 保存会话变量,请参考这里
我有以下作为我要测试的代码:
<body onload='load_data();'>
<script type='text/javascript'>
// global object
var store;
function load_data() {
// load persistent store after the DOM has loaded
store = new Persist.Store('My Application');
store.set('some_key', 'this is a bunch of persistent data');
// get value from store and prompt user
store.get('some_key', function(ok, val) {
if (ok)
alert('some_key = ' + val);
});
//remove value
store.remove('some_key');
//display removed store
store.get('some_key', function(ok, val) {
if (ok)
alert('some_key = ' + val);
});
}
</script>
</body>
代码在检索设置值时工作正常,但是,在删除项目时,脚本崩溃并且错误如下:
TypeError: this.getItem is not a function
val = this.getItem(key);
这里出了什么问题?