如果通过cookies和localStorage取值?
2024-10-07 18:48:05
1. getCook :
设定setCookie值
let setCookie = setCookie('wan',data,7);
function setCookie(c_name,value,expiredays){
var exdate=new Date()
exdate.setDate(exdate.getDate()+expiredays)
document.cookie=c_name+ "=" +escape(value)+
((expiredays==null) ? "" : ";expires="+exdate)
}
获取getCookie
let getCookie = getCookie('wan');
function getCookie(c_name){
if (document.cookie.length>0){
var c_start=document.cookie.indexOf(c_name + "=")
if (c_start!=-1){
c_start=c_start + c_name.length+1
var c_end=document.cookie.indexOf(";",c_start)
if (c_end==-1) c_end=document.cookie.length
return unescape(document.cookie.substring(c_start,c_end))
}
}
return undefined;
}
localStorage取值?
window.localStorage.setItem("headers_vendor", wxHeaders); 设定
window.localStorage.getItem("headers_vendor"); 取值
localStorage:常用的api
添加键值对:localStorage.setItem(key,value)
获取键值:localStorage.getItem(key)
删除键值对:localStorage.removeItem(key)。
清除所有键值对:localStorage.clear()。
获取localStorage的属性名称(键名称):localStorage.key(index)。
最新文章
- {Reship}{KMP字符串匹配}
- 转载---ViewPager,PagerAdapter,FragmentPagerAdapter和FragmentStatePagerAdapter的分析对比
- cookie的操作
- POJ 2449 A*+SPFA
- sharepoint 中用自带的download.aspx实现文件的下载,中文文件名编码的问题
- [TypeScript] Stopping a TypeScript Build When Errors Are Found
- SQL分页小Demo
- C# 文件读写异常“正由另一进程使用,因此该进程无法访问该文件”
- 本地yum源安装GCC
- Qt 外观之一 ——Qt Style Sheet
- Django中templates使用的补充
- java流和文件 保存字节级数据(写)
- 装饰器,栈 ,asyncio 代码
- Excel中快捷键Ctrl+End覆盖过多
- JNI编程实现(Windows)
- Java文档注释导出帮助文档和项目的jar包导入和导出。
- Linux基础命令-mkdir
- git基础使用——TortoiseGit
- Qt监控Arduino开关状态(读取串口数据)
- centos7虚拟机安装elasticsearch6.4.x-遇到的坑