JS 設置/獲取session
阿新 • • 發佈:2019-02-12
.com res isa remove session jquer n) locals 取數
localStorage.setItem("b","isaac");//設置b為"isaac"
var a1 = localStorage["a"];//獲取a的值
var a2 = localStorage.a;//獲取a的值
var b = localStorage.getItem("b");//獲取b的值
localStorage.removeItem("c");//清除c的值
設置:
1 . $.session.set(‘token‘, result.accessToken) 這個要引用庫jquerySession.js
2. sessionStorage.setItem("token", result.accessToken);
3. localStorage.setItem("token", result.accessToken);
獲取:
1. ourtoken = $.session.get(‘token‘);
2. ourtoken = sessionStorage.getItem("token"); 這個同頁面可以,跨頁不行
3. ourtoken = localStorage.getItem("token"); 這個跨頁也可以
添加數據
$.session.set(‘key‘, ‘value‘)
刪除數據
$.session.remove(‘key‘);
獲取數據
$.session.get(‘key‘);
清除數據
$.session.clear();
--------------------------------------
localStorage.a = 3;//設置a為"3"
localStorage["a"] = "sfsf";//設置a為"sfsf",覆蓋上面的值
var a1 = localStorage["a"];//獲取a的值
var a2 = localStorage.a;//獲取a的值
var b = localStorage.getItem("b");//獲取b的值
localStorage.removeItem("c");//清除c的值
參考:https://www.cnblogs.com/LChenglong/p/8006197.html
JS 設置/獲取session