JavaScript操作Cookie

js 代码
  1. <script>   
  2. function setCookie(name,value)   
  3. {   
  4.  var Days = 30; //此 cookie 将被保存 30 天   
  5.  var exp = new Date(); //new Date("December 31, 9998");   
  6.  exp.setTime(exp.getTime() + Days*24*60*60*1000);   
  7.  document.cookie = name + "="+ escape (value) + ";expires=" + exp.toGMTString();   
  8. }   
  9. function getCookie(name)   
  10. {   
  11.  var arr = document.cookie.match(new RegExp("(^| )"+name+"=([^;]*)(;|$)"));   
  12.  if(arr != null) return unescape(arr[2]); return null;   
  13. }   
  14. function delCookie(name)   
  15. {   
  16.  var exp = new Date();   
  17.  exp.setTime(exp.getTime() - 1);   
  18.  var cval=getCookie(name);   
  19.  if(cval!=null) document.cookie= name + "="+cval+";expires="+exp.toGMTString();   
  20. }   
  21.   
  22. setCookie("aaa","呵呵");   
  23. alert(getCookie('aaa'));   
  24. </script>   

 

Cookie类

 

js 代码
  1. <script language="JScript">   
  2. function Cookie(delim){//操作Cookie类   
  3.   Array.prototype.splice=function(){   
  4.     var len=arguments.length,tarray=[],i=arguments[0]+arguments[1];   
  5.     if(len>1){   
  6.       while(i<this.length)tarray[tarray.length]=this[i++];   
  7.       this.length=arguments[0];   
  8.       if(len>2)for(var i=2;i<len;i++)this[this.length]=arguments[i];   
  9.       var tlen=tarray.length,i=0;   
  10.       while(i<tlen)this[this.length]=tarray[i++];   
  11.       }   
  12.     return this;   
  13.     }   
  14.   this._Cookie=[];   
  15.   this.Load=function(){   
  16.     if(document.cookie.indexOf(";")!=-1){   
  17.       var _sp,_name,_tp,_tars,_tarslength;   
  18.       var _item=document.cookie.split("; ");   
  19.       var _itemlength=_item.length;   
  20.       while(_itemlength>0){   
  21.         _sp=_item[--_itemlength].split("=");   
  22.         _name=_sp[0];   
  23.         _tp=_sp[1].split(",");   
  24.         _tars=_tp.slice(1,_tp.length);   
  25.         this._Cookie[_name]=[];   
  26.         this._Cookie[_name]=_tars;   
  27.         this._Cookie[_name]["timeout"]=_tp[0];   
  28.         }   
  29.       return true;   
  30.       }   
  31.     return false;   
  32.     }   
  33.   this.Save=function(){   
  34.     var _str,_ars,_mars,_marslength,timeout,i,key;   
  35.     for(key in this._Cookie){   
  36.       if(!this._Cookie[key])return;   
  37.       _str=[];   
  38.       _mars=CookieClass._Cookie[key];   
  39.       _marslength=_mars.length;   
  40.       for(i=0;i<_marslength;i++)_str[_str.length]=escape(_mars[i]);   
  41.       document.cookie=key+"="+_mars["timeout"]+(_str.length>0?",":"")+_str+";expires="+new Date(parseInt(_mars["timeout"])).toGMTString();   
  42.       }   
  43.        
  44.     }   
  45.   this.GetCookieCount=function(){   
  46.     var _length=0,key;   
  47.     for(key in this._Cookie)_length++;   
  48.     return _length;   
  49.     }   
  50.   this.Create=function(name,days){   
  51.     this._Cookie[name]=[];   
  52.     this._Cookie[name]["timeout"]=new Date().getTime()+days*86400000;   
  53.     }   
  54.   this.Modify=function(name,days){   
  55.     this.Create(name,days);   
  56.     }   
  57.   this.Delete=function(name){   
  58.     this.Create(name,0);   
  59.     }   
  60.   this.AddItem=function(name,value){   
  61.     this._Cookie[name][this._Cookie[name].length]=value;   
  62.     }   
  63.   this.DelItem=function(name,index){   
  64.     this._Cookie[name].splice(index,1);   
  65.     }   
  66.   this.GetCount=function(name){   
  67.     return this._Cookie[name].length;   
  68.     }   
  69.   this.GetItem=function(name,index){   
  70.     return this._Cookie[name][index];   
  71.     }   
  72.   }   
  73. </script>   
  74. <script language="JScript">   
  75. /*  
  76. ====================================  
  77. Design :Flashsoft  
  78. ====================================  
  79. 浏览器能够通过Cookies保留有关数据。象Windows的注册表一样,用户不必知道Cookies的具体位置,浏览器能找到这些数据。第六代的浏览器,不管是IE还是NS都支持document.cookie属性。通过这个属性来读取或修改Cookies的值。不过Cookies的存储形式是非结构化的长字符串,需要经过相应的解析后才有意义。  
  80.  
  81. Cookies的表达如下,除了name=value以外,其它均为可选:  
  82. name=value;   
  83. expires=date;  
  84. domain=domainname  
  85. path=pathname;  
  86. secure;  
  87.  
  88. 例如:  
  89. User=HockeyDude; expires=Thu,01-Jan-70 00:00:01 GMT; domain=www.mydomain.com; path=/images; secure;  
  90. Pass=Gretzky; expires=Thu,01-Jan-70 00:00:01 GMT; domain=www.mydomain.com; path=/images; secure;  
  91.  
  92. 这么长的两个字符串只代表了两个Cookies。如果还要再加上电子信箱或其他信息就还得加长字符串。通常都是通过分解这样的字符串来取得各个变量或元素的。这实在是费时费力的事。  
  93.  
  94. 我使用面向对象设计(Object Oriented Design,OOD)的思路来编写Cookies处理函数,其特点如下:  
  95.  
  96. 便于增删子项。这是很重要的,有些浏览器限制Cookies的使用数量。  
  97. 通过修改函数可以容易地修改时效数据。通常的做法很麻烦,要拷贝Cookies,删除原Cookies,修改并重写Cookies。  
  98. Cookies和它的子项存放在数组里。可以根据需要快速而有效地进行修改。这样也无须解析那长长的字符串。  
  99.  
  100. Cookies对象的使用  
  101. 以下是对象的公有方法:  
  102.  
  103. 方括号[]内是可选参数  
  104. //构造  
  105. Cookie([定界符,缺省为句点]) - 构造函数  
  106.  
  107. //初始化  
  108. GetCookieCount() - 返回Cookies数量  
  109. Create(name, days) - 创建Cookies及其时效天数  
  110. Modify(name, days) - 修改Cookies的时效天数  
  111. Delete(name) - 删除Cookies及其子项  
  112. GetCount(name) - 返回Cookies的子项数量  
  113. AddItem(name,value) - 增加一个子项  
  114. GetItem(name,index) - 返回指定索引的子项  
  115. DelItem(name,index) - 删除指定的子项  
  116.  
  117. //存取  
  118. Load() - 读取Cookies  
  119. Save() - 存储Cookies  
  120.  
  121. 下面是应用实例:  
  122. */  
  123. var CookieClass=new Cookie();   
  124. if(!CookieClass.Load()){   
  125.   CookieClass.Create("Pass",1);   
  126.   CookieClass.Create("User",1);   
  127.   CookieClass.AddItem("Pass","Ps1");   
  128.   CookieClass.AddItem("Pass","Ps2");   
  129.   CookieClass.AddItem("Pass","Ps3");   
  130.   CookieClass.AddItem("Pass","Ps4");   
  131.   CookieClass.AddItem("Pass","Ps5");   
  132.   CookieClass.AddItem("Pass","Ps6");   
  133.   CookieClass.DelItem("Pass",1);   
  134.   CookieClass.Save();   
  135.   }   
  136. alert(document.cookie);   
  137. </script>   
告别VLC!用Python+OpenCV实时拉取RTSP监控流,并实现抽帧降低延迟(附完整代码) 本文介绍了一种基于Python和OpenCV的低延迟RTSP监控流处理方案,通过抽帧技术显著降低延迟并保持视频分析准确性。文章详细讲解了RTSP流处理的基础挑战、抽帧技术原理与实现,以及完整的低延迟处理方案,包括硬件加速配置和动态抽帧算法,帮助开发者优化监控视频流处理性能。 阅读详情

相关推荐

一个响应ping包延迟偏大的问题

前段时间客户反馈一个使用pc上的命令行ping无线设备(WiFi4)时,设备平均响应时间(测试时长2小时,1秒Ping一次)相比其它机型偏慢的问题,并上传上具体的时间的Log.从log中看到,大多数包的响应还是比较快的,只是个别响应时间较长,且响应时间长的包时间几乎都是一样的100多ms.如下是部分响应时间截图. 整个2小时的测试时间里,总是时不时的出这么上102,104ms的响应时间,这直接导致了平均响应时间被拉大.于是本地测试,也发现了类似的延迟.本地测试时,现象略有...

流风回雪的博客 1万+

js操作cookies的类

  js 代码 &lt;script language=&lt; span=""&gt;"JavaScript"&gt;       function Cookie(delim){//操作Cookie类        Array.prototype.splice=function(){            var len=arguments.leng...

coolmaple 198

保姆级教程:在RK3568开发板上手把手配置RMII百兆以太网DTS节点

本文提供了一份详细的RK3568开发板RMII百兆以太网DTS节点配置教程,涵盖基础概念解析、关键参数设置、实际操作步骤及常见问题排查。通过手把手指导,帮助开发者快速完成RK3568开发板的以太网配置,特别适合嵌入式系统开发者参考。

weixin_33686714的博客 137

Cookie操作类2(js)

<script> functioneyunCookie() {this.key="";//初始化key。 this.value="";//初始化key'svalue。 this.expires=0;//初始化cookie的有效时间,单位毫秒。 this.init=function()//对象初始化 ...

weixin_30695195的博客 177

深入解析时钟同步技术:相位同步、频率同步与同源时钟的实战应用

本文深入解析时钟同步技术的三种核心方式:相位同步、频率同步与同源时钟,详细阐述其技术原理、实现方案及实战应用。通过对比分析不同同步方式的特点与适用场景,为电子系统设计提供选型指南,帮助工程师优化时钟网络设计,提升系统稳定性和性能。

weixin_29240711的博客 449

STM32H743的ADC还能这么玩?定时器触发+DMA搬运,构建低CPU占用的数据流

本文深入探讨了STM32H743微控制器中ADC的高效使用方法,通过定时器触发和DMA搬运技术实现低CPU占用的数据流采集。详细解析了硬件架构、CubeMX配置步骤及高级优化技巧,包括双缓冲技术和多ADC同步采样,适用于电机控制、音频采集等高性能应用场景。

weixin_30698527的博客 647

Cookie操作公共方法类

using System; using System.Web; namespace AmwITx.Framework.Web.Components { /// &lt;summary&gt; /// Cookie /// &lt;/summary&gt; public class Cookie { private C...

weixin_33725722的博客 182

Android Audio常见问题分析方法

分析audio dump,确定写给BT的data是否正常,MTK平台Android原生架构分析threadloop write节点,高通平台分析QXDM 1586节点,从dump确定问题大概位置。分析systrace 确定性能。AudioFocus状态(用于播放或者音量异常的情况)。AudioTrack是否正常创建bt连接是否正常通路异常,setMode,setSpeakerphoneOn等都会影响设备选择,sco调用流程是否正常。

一条老狗的博客 2388

Cookie实现自动登录案例实现

分析: 在这里我采用了用原生js判断用户名密码和cookie中保存的用户名密码比较 Servlet步骤: 获取文本框中的用户名和密码 判断用户名密码是否正确,实现登录 如果登录成功,就判断用户是否勾选了记住我按钮 用户勾选了按钮之后,就把用户名和密码存到Cookie中,保存一定的时间 跳转到登录成功页面 用户名密码错误跳转到登录失败页面 Servlet代码: package com.a...

qq_44890539的博客 6644

基于STM32单片机的智能分拣系统

基于STM32单片机的智能分拣系统是一种高效、精准的自动化分拣解决方案,适用于物流、仓储、制造业等领域。该系统利用STM32单片机作为核心控制器,结合传感器技术、电机控制算法和通信模块,实现对物品的自动识别、分类和分拣。通过智能化的设计,该系统能够大幅提高分拣效率,降低人工成本,并减少错误率。基于STM32单片机的智能分拣系统是一种高效、精准、低成本的自动化解决方案,能够广泛应用于物流、制造、环保等领域。

qq_62634009的博客 1940

手把手教你学Simulink——基于Simulink的蚁群算法路径规划仿真建模示例

路径规划是机器人导航系统中的核心任务之一,旨在为机器人找到一条安全且高效的路径,使其能够从起点到达目标点,同时避免与障碍物发生碰撞。在开始之前,需要定义工作环境(例如地图),包括起点、终点以及可能存在的障碍物位置。通过本指南,我们介绍了如何基于Simulink结合MATLAB实现蚁群算法的路径规划仿真建模。

MHD0815的博客 222

js使用cookies存取用户名和密码

//记录Cookie function SetCookie(name, value, days){     var finalDays = 7; //cookie存储时间默认7天     if (typeof (days) != "undefined" && !isNaN(days)){         finalDays = parseInt(days);     }     var

w1428002522的专栏 5388

SQL面试题——抖音SQL面试题 股票波峰波谷

这个题目的难度比较低,我们是用lead 和 lag 两个函数就可以搞定,也就是在一个SQL 里面同时使用多个函数,问题的考查点在于对边界的考虑。

2万+

JavaScript Cookie操作终极指南:js-cookie完整使用教程

想要在浏览器中轻松处理Cookie操作吗?js-cookie是一个简单、轻量级的JavaScript API,专门用于处理浏览器Cookie。这款强大的工具支持各种浏览器,没有依赖,体积小于800字节,是前端开发的必备利器!😊 ## 为什么选择js-cookie? 在Web开发中,Cookie处理是必不可少的功能。js-cookie提供了以下核心优势: ✨ **超轻量级** - 压缩后小于

gitblog_00190的博客 493

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

WINCC7.3破解文件

WINCC7.3硬件够破解文件,有需要的下载!WINCC7.3硬件够破解文件,有需要的下载!

js java cookie_JavaScript操作和使用Cookie

Cookie概述Cookie是由服务器端生成并储存在浏览器客户端上的数据。在javaweb开发中Cookie被当做java对象在web服务器端创建,并由web服务器发送给特定浏览器客户端,并且web服务器可以向同一个浏览器客户端上同时发送多个Cookie,每一个Cookie对象都由name和value组成,name和value只能是字符串类型,浏览器接收到来自服务器的Cookie数据之后默认将其保...

weixin_34526937的博客 344

文档:亲测可用解决vnc灰屏,黑屏,鼠标大黑叉情况

主要解决vnc-viewer灰屏,黑屏,鼠标大黑叉等现象,详细见文档。

JS Javascript 操作Cookie

--未测试 留着参考 中文时可以用 unescape、escape 或是 encodeURI、decodeURI 进行转换 一: JS操作cookie.html ` //用法: //一、设置cookie var cookie = new Cookies(); function set() {

·Lee 786

android 蓝牙通讯demo

android 下蓝牙通讯demo,实现了发现蓝牙,使能蓝牙,通过蓝牙发送消息。

js javaScript 操作cookie

<br /> String.prototype.Trim = function() { return this.replace(/^/s+/g,"").replace(//s+$/g,""); } function JSCookie() { this.GetCookie = function(key) { var cookie = document.cookie; var cookieArray

hoojo 2340

JavaScript 2.5 js操作cookie

一、获取cookie let cookieArr = document.cookie.split(";"); let obj = {} cookieArr.forEach((i)=>{ let arr = i.split("="); obj[arr[0]] = arr[1]; } ); console.table(obj); 二、修改cookie

LetsStudy的博客 363

js中cookie的操作

//cname:cookie的名称,cvalue:cookie的内容,exdays:cookie有效期时长; function setCookie(cname, cvalue, exdays) { var d = new Date(); // d.setTime(d.getTime() + (exdays*1000));//设置过期时间是多少天后; // d.setTime(d...

图纸的博客 207

JavaScript Cookie操作全解析:从原生API到js-cookie实战

在Web开发中,本地存储是构建交互式应用的基础技术之一,它允许浏览器在客户端持久化数据,以实现状态管理和个性化体验。其核心原理是通过浏览器提供的存储接口,将数据以键值对形式保存在用户本地,并在后续页面访问或请求中读取使用。这项技术的价值在于它能够减少服务器负载、提升用户体验并实现无状态HTTP协议下的会话保持。常见的应用场景包括用户登录态管理、个性化设置保存以及跨页面数据传递。本文聚焦于Cookie这一经典的本地存储方案,深入探讨其原生API操作、属性配置以及如何通过封装或使用第三方库(如js-cookie

weixin_30368981的博客 312

帮助你简化Cookie操作的javascript类库 - cookie.js

为什么80%的码农都做不了架构师?>>> ...

weixin_34293902的博客 98

如何使用 JavaScript 操作 Cookie?

Cookie 是存储在用户浏览器中的小块数据,通常用于在客户端保存用户信息。服务器可以通过 Cookie 在请求中读取这些数据。常见的用途包括保存用户登录状态、语言设置、主题偏好等。Cookie 是键值对Cookie 的生命周期:可以设置为会话级(浏览器关闭后失效)或持久性(设置过期时间)。JavaScript 提供了强大的 Cookie 操作功能,可以在客户端存储和读取信息。通过设置、获取、删除 Cookie,您可以实现许多常见的功能,如用户登录状态、语言偏好等。

向着太阳迎着光 3402

浏览器中使用JS操作Cookie详解

如何在浏览器端操作Cookie?这里有原生JS、jQuery Cookie、js-cookie,总有一种适合你。

丹丹的后花园 4626

javascript 操作cookie详解

设置cookie 每个cookie都是一个名/值对,可以把下面这样一个字符串赋值给document.cookie: document.cookie="userId=828"; 如果要一次存储多个名/值对,可以使用分号加空格(; )隔开,例如: document.cookie="userId=828; userName=hulk"; 在cookie的名或值中不能使用分号(;)、逗

杉楂的博客 5655

js操作cookie

直接上代码吧,清楚明了。 cookie的查看局势到cookie的路径下看看打开文件,看看有没有。(记得右键刷新) <% String path = request.getContextPath(); %> <% //Cookie coo1 = new Cookie("key1", "value1"); //coo1.setMaxAge(60000); //coo1.

1170
上一篇: 不用框架,也做背景音乐
下一篇: 一个IP建多个Web站点
普通网友
博客等级 码龄21年 1粉丝 6原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值