当前位置:网站首页>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>
边栏推荐
- Zero training platform course-1. SQL injection Foundation
- Codeforces Round #810 (Div.2) A-C
- The token verification of applet message push configuration failed. Please check and confirm
- Shell enterprise interview exercise
- 抽象工厂模式
- [QT] unable to open the containing file pcap.h (C1083) in QT creator
- Closed hash and open hash resolve hash conflicts
- Temperature and humidity measurement and display device based on Arduino
- ChromeDriver下载-自用
- Install tensorflow
猜你喜欢

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

Record a pit dug by yourself~

linux能不能安装sqlserver

什么是真正的 HTAP ?(二)挑战篇

小程序支付管理-新版支付对接流程

【Day42 文献精读】A Bayesian Model of Perceived Head-Centered Velocity during Smooth Pursuit Eye Movement

ADC噪声全面分析 -01- ADC噪声的类型以及ADC特性

DEMO:PA30 银行国家码默认CN 增强

Synchronized lock

10000 word parsing MySQL index principle -- InnoDB index structure and reading
随机推荐
User unlock sm04 sm12
Understanding and learning of node flow and processing flow in io
ChromeDriver下载-自用
API version control [eolink translation]
Chromedriver download - self use
How to get DDL information of an object
JS存取cookie示例
C# 中的转译字符'/b'
存储过程与函数
Installation and use of apifox
Shell condition test, judgment statement and operator of shell system learning
软件调优方法有哪些?看看飞腾技术专家怎么说 | 龙蜥技术
反弹shell是什么?反弹shell有什么用?
npm的使用
如何在 60 秒内去分析和定位问题?
面试复盘五
【StoneDB Class】入门第一课:数据库知识科普
【Golang】golang开发微信公众号网页授权功能
C语言:随机生成数+希尔排序
MySQL table name area in Linux is not case sensitive