(function (win,doc) { var local_storage = { //创建localstorage @param argument json || string items: function (argument) { if (typeof argument == ‘object‘) { //创建 for (var i in argument) { win.localStorage.setItem(i, argument[i]); } } else if (typeof argument == ‘string‘) { //获取 return win.localStorage.getItem(argument); } else { return console.error(‘参数只能是json或者string‘); } }, //删除localstorage @param val string || null rmitems: function (val) { if (val) { win.localStorage.removeItem(val); } else { var json = window.localStorage; for (var i in json) { win.localStorage.removeItem(i); } } } } win.local_storage =local_storage ;
})(window,document);用个js来装载,要用的时候直接调用还是很方便的,用json格式来装载,直接在另一个js里调用:如 local_storage .items({name:‘哈哈‘,age:12});就可以直接用把长的代码简单化
时间: 2024-11-06 03:28:43