<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="description" content="">
<meta name="HandheldFriendly" content="True">
<meta name="MobileOptimized" content="320">
<meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
<title>cookies</title>
<!-- html5.js for ie less than 9 -->
<!--[if lt ie 9]>
<script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script>
<![endif]--> <!-- css3-mediaqueries.js for ie less than 9 -->
<!--[if lt ie 9]>
<script src="http://css3-mediaqueries-js.googlecode.com/svn/trunk/css3-mediaqueries.js"></script>
<![endif]-->
<style type="text/css">
body,div,ul,li,a,img,h1,h2,h3,h4,h5,p,input{
margin:0;
padding:0;
}
article, aside, details, figcaption, figure, footer, header, hgroup, menu, nav, section {
display: block;
}
body{
font-family:"微软雅黑",Verdana, Arial, Helvetica, sans-serif;
-webkit-text-size-adjust:none;
}
img,input{
outline:none;
}
ul{
list-style:none;
}
a:link{
text-decoration:none;
color:#545454;
}
a:visited{
color:#525252;
}
a:hover{
color:#4D4D4D;
}
.clear{
clear:both;
}
.ui-page {
-webkit-backface-visibility: hidden;
}
</style>
</head>
<body>
<div id="time"></div>
<script src="jquery.js"></script>
<script type="text/javascript">
(function(){
var time=new Date();
var str;
str=time.getSeconds();
$(window).click(function(){
Cookies.set('istime',str);
})
var Cookies ={
//设置cookies
set:function(name,value,days){
if (days) {
var date = new Date();
date.setTime(date.getTime()+(days*24*60*60*1000));
var expires = "; expires="+date.toGMTString();
}
else var expires = "";
document.cookie = name+"="+value+expires+"; path=/";
}, //获取cookies
get:function(name){
var nameEQ = name + "=";
var ca = document.cookie.split(';');
for(var i=0;i < ca.length;i++) {
var c = ca[i];
while (c.charAt(0)==' ') c = c.substring(1,c.length);
if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
}
return null;
}, //清除cookies
erase:function(name){
this.set(name,"",-1);
}
} var isTime = function(){
var _istime = Cookies.get('istime'); //获取name为'istime'的cookies;
if(_istime ){ //判断name为'istime'的cookies存不存在;
var time1=new Date();
var str1;
str1=time.getSeconds(); if(str1 - _istime > 0 ){
alert(str1 - _istime);
} }
}; $(function(){
isTime();
})
})(this) </script>
</body>
</html>

js设置、获取、清除cookie的更多相关文章

  1. 【转】分享前端开发中通过js设置/获取cookie的一组方法

    在前端开发中,通常都需要获取并记录用户的某些操作设置,这样可以使用户下一次访问网站时不用进行重复的调整设置同一个功能. js方法的完整代码如下: var cookie = { set:function ...

  2. springboot项目:登录 登录aop拦截 使用Redis与cookie 进行设置获取清除操作

    登录.登出: 第一步:在pom文件中引入依赖 <dependency> <groupId>org.springframework.boot</groupId> &l ...

  3. js 设置 获取css样式

    先看一段代码,为了体现一会下面说的js用style获取css样式的不同 一:给div设置margin-left(用style设置css样式没什么问题) box.style.marginLeft=&qu ...

  4. JS设置获取cookies

    结合JavaScript权威指南,加上项目开发时在网上搜集的资料,整理了两种设置和获取cookie的方法. <script> //设置cookie  方法一function setCook ...

  5. vue 存取、设置、清除cookie

    步骤: 第一步:assets目录下添加cookie.js文件 export function setCookie(c_name,value,expire) { var date=new Date() ...

  6. js保存,获取,删除cookie的操作

    [转]来自:http://blog.csdn.net/itmyhome1990/article/details/7363816 JSP表单页面 <form action="login& ...

  7. 如何设置,获取,删除cookie?

    cookie : 存储数据,当用户访问了某个网站(网页)的时候,我们就可以通过cookie来像访问者电脑上存储数据 1.不同的浏览器存放的cookie位置不一样,也是不能通用的 2.cookie的存储 ...

  8. js设置和读取cookie

    /*path参数:表示cookie所在的目录,.net默认为/(根目录).在同一个服务器上有目录如下:/test/,/test/aa/,/test /bb/,现设一个cookie1的path为/tes ...

  9. js设置、获取单值cookie和多值cookie

    js设置.获取单值cookie和多值cookie,代码如下: var CookieUtil = (function () { var Cookie = function () { // 获取单值coo ...

  10. Js设置及获取Cookie的方法

    Login页面设置Cookie: <script type="text/javascript"> if(json.result=="true") { ...

随机推荐

  1. UILabel常用属性小结

    标签常用的属性: (1)frame属性:设置标签的位置与大小. frame = CGRectMake(CGFloat x, CGFloat y, CGFloat width, CGFloat heig ...

  2. 微信小程序实操-image height:auto问题,url地址报错,“不在以下合法域名列表中”问题等

    1.修改app顶部title 使用API: wx.setNavigationBarTitle({ title: 'titleName'}); 2.ajax请求 wx.request({ url: 'h ...

  3. SVN和Git的一些用法总结

    (A)SVN (1)查看日志提交的时候一般会写上注释,如果要查看提交日志,用以下命令: 1 svn log -l 4 其中,-l 4表示只查看最近4条日志(也可以没有这样的参数,就表示查看所有日志). ...

  4. bzoj1113

    传送门:http://www.lydsy.com/JudgeOnline/problem.php?id=1113 题解:单调栈 代码: #include<iostream> #includ ...

  5. PHP文件夹文件拷贝/复制函数 dir_copy($src = '', $dst = '')

    /* * 文件夹文件拷贝 * * @param string $src 来源文件夹 * @param string $dst 目的地文件夹 * @return bool */ function dir ...

  6. delphi公用函数

    {*******************************************************} { } { Delphi公用函数单元 } { } { 版权所有 (C) 2008 } ...

  7. 才一年,H5的发展就成这样了......

    关于H5的发展,分享几个最近看到的惊人数据和新闻: 1.截至2015,有80%的App将全部或部分基于HTML5.这意味着大部分App的内容都将是以网页的形式呈现,典型的例子包括微信.Facebook ...

  8. js原生继承之——构造函数式继承实例

    <!DOCTYPE html><html lang="en"><head>    <meta charset="UTF-8&qu ...

  9. 使用(Drawable)资源——图片资源

    图片资源是最简单的Drawable资源,只要把*.png.*.jpg.*.gif等格式的图片放入/res/drawble-xxx目录下,Android SDK就会在编译应用中自动加载该图片,并在R资源 ...

  10. Unity 绘图性能优化 - Draw Call Batching

    Unity 绘图性能优化 - Draw Call Batching Unity官方链接:http://docs.unity3d.com/Manual/DrawCallBatching.html 转载请 ...