当前位置:网站首页>JS access cookie example
JS access cookie example
2022-07-27 07:50:00 【Running lion a】
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<script src="js/jquery-2.2.1.min.js"></script>
<body>
<input id="username" />
<button id="write"> assignment cookie</button>
<button id="read"> Value cookie</button>
<span id="cookie"></span>
</body>
</html>
<script> $("#write").click(()=>{
let username = $("#username").val(); console.log(username); setCookie("userName",username,1); }) $("#read").click(()=>{
//cookie Value : var cookie = getCookie("userName"); console.log(cookie) $("#cookie").html(cookie); }) /** * default cookie Write method * @param name cookie Of key Example :userName * @param value cookie Of value Example : Zhang San * @param time cookie Storage time , With ' God ' In units of Example :1 */ function setCookie(name,value,time){
var Days = time; var exp = new Date(); exp.setTime(exp.getTime() + Days*24*60*60*1000); document.cookie = name + "="+ encodeURI (value) + ";expires=" + exp.toGMTString()+";path=/"; } /** * obtain Cookie The value in * @param objName * @returns */ function getCookie(objName){
// Gets the... Of the specified name cookie Value var arrStr = document.cookie.split("; "); for (var i = 0; i < arrStr.length; i++) {
var temp = arrStr[i].split("="); if (temp[0] == objName){
return decodeURI(temp[1]); } } } </script>
边栏推荐
- How to get DDL information of an object
- Multi condition query of when
- 大家节日快乐哈
- What other methods are available for MySQL index analysis besides explain
- 安装tensorflow
- Leetcode54. 螺旋矩阵
- JS存取cookie示例
- Pg_ relation_ Size question
- Closed hash and open hash resolve hash conflicts
- Usage scenarios for automated testing
猜你喜欢

【QT】capture. Obj:-1: error: lnk2019: unresolved external symbols__ imp_ Htons (solution)

增强:BTE流程简介

Comprehensive analysis of ADC noise-01-types of ADC noise and ADC characteristics

杂谈:手里有竿儿,肩上有网,至于背篓里有多少鱼真的重要吗?

Stored procedures and functions

综合案例、

企业架构驱动的数字化转型!

Gossip: is rotting meat in the pot to protect students' rights and interests?

Understanding and learning of node flow and processing flow in io

IDEA中文乱码怎么办
随机推荐
shell企业面试题练习
C language: random generated number + insertion sort
正则 和 sed 练习
JS regular expression implementation adds a comma to every three digits
[stonedb class] introductory lesson 1: popular science of database knowledge
Gossip: is rotting meat in the pot to protect students' rights and interests?
Convert objects to key value pairs
slf4j如何进行logback配置呢?
Understanding and learning of properties class and properties configuration file
C#委托的使用案例
Lua迭代器
【已解决】新版Pycharm(2022)连接服务器进行上传文件报错“Command rsync is not found in PATH”,无法同步文件
Promise详解
软件调优方法有哪些?看看飞腾技术专家怎么说 | 龙蜥技术
Zero training platform course-1. SQL injection Foundation
电子量产项目框架--基本思想
企业架构驱动的数字化转型!
C# 中的转译字符'/b'
yhb_ sysbench
DEMO SUBMIT 某程序并获取该程序ALV数据