mcya / JavaScriptExperience

👮 JavaScript Experience for web(JavaScript归类:简单入门+数组+经典循环+字符串+函数+Date日期+简单对象+BOM+DOM) +[ Issues(js实用技巧)]
29 stars 8 forks source link

js/jq localStorage #10

Open mcya opened 7 years ago

mcya commented 7 years ago
JS下的操作方法(值的获取和设置可以分两种方式)
获取值1:localStorage.getItem(“key”)
设置值1:localStorage.setItem(“key”,”value”)

获取值2:localStorage.keyName
设置值2:localStorage.keyName = “value”

清除值:localStorage.removeItem(“key”)
清除所有值:localStorage.clear()

JQ下的操作方法(相当于JS方法前加”window.”)

获取值1:window.localStorage.getItem(“key”)
设置值1:window.localStorage.setItem(“key”,”value”)

获取值2:window.localStorage.keyName
设置值2:window.localStorage.keyName = “value”

清除值:window.localStorage.removeItem(“key”)
清除所有值:window.localStorage.clear()
mcya commented 7 years ago

存取对象


function updateChannel(){
    var records = getSelectedRecords('grid');
    if(records.length == 0){
        dialogUtil.alert('请选择需要操作的记录!',true);
        return false;
    }
    records = JSON.stringify(records); //JSON.stringify装换成json
    indow.localStorage.setItem("records", records); //存数据
    console.log('获取本地存储的数据', JSON.parse(localStorage.getItem("records"))) //JSON.parse编译localStorage.getItem获取到的数据
    window.location.href=path+"/pages/params/email/emailAdd.jsp?isUpdate=1"
}

//存取之后到其他页面也可以获取,现在这里这么写只是为了能够更加直观地体现出来。