This article is a detailed introduction to the solution to jquery forcing cookie invalidation. Friends who need it can come and refer to it. I hope it will be helpful to everyone
Method 1:
var date = new Date(); date.setTime(date.getTime() + (x * 60 * 1000)); $.cookie('example', 'foo', { expires: date });
Method two:
<script type="text/javascript"> var expiresDate= new Date(); expiresDate.setTime(expire.getTime() + (? * 60 * 1000)); //?替换成分钟数如果为60分钟则为 60 * 60 *1000 $.cookie("__cookie__", 'helloworld', { path : '/', //cookie的作用域 expires : expiresDate }); } </script>
Method three:
function SetCookie(name,value){ var str=name+"="+escape(value); var dd = new Date(); dd.setDate(dd.getDate()+1);//获取明天 var y = dd.getYear(); var m = dd.getMonth()+1;//获取当前月份的日期 var d = dd.getDate(); date = new Date(y+'-'+m+'-'+d+' 00:00:00'); date.setTime(date.getTime());//明天的0:00:00 str+=";expires="+date.toGMTString(); document.cookie = str; }
The above is the summary of this article for everyone. I hope you will like it.
For more related tutorials, please visit JavaScript Video Tutorial