document.cookie
2016-07-08 18:03
543 查看
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>last</title>
<script type="text/javascript">
var Yugi =
{
supportSessionStorage : !!window.sessionStorage,
getRadio : function (name)
{
if (Yugi.supportSessionStorage)
{
return Yugi.readSessionStorage (name);
}
else
{
return Yugi.readCookie (name);
}
},
setRadio : function (name, value)
{
if (Yugi.supportSessionStorage)
{
Yugi.writeSessionStorage (name, value);
}
else
{
Yugi.writeCookie (name, value, 1);
}
},
writeSessionStorage : function (name, value)
{
window.sessionStorage.setItem (name, value);
},
readSessionStorage : function (name)
{
return window.sessionStorage.getItem (name);
},
writeCookie : function (name, value, hours)
{
var expire = "";
if (hours != null)
{
expire = new Date ((new Date ()).getTime () + hours * 3600000);
expire = "; expires=" + expire.toGMTString ();
}
document.cookie = name + "=" + escape (value) + expire;
},
readCookie : function (name)
{
var cookieValue = "";
var search = name + "=";
if (document.cookie.length > 0)
{
offset = document.cookie.indexOf (search);
if (offset != -1)
{
offset += search.length;
end = document.cookie.indexOf (";", offset);
if (end == -1)
end = document.cookie.length;
cookieValue = unescape (document.cookie.substring (offset, end))
}
}
return cookieValue;
}
};
window.onload = function ()
{
var rdos = document.getElementsByName ('rdo');
for ( var i = 0; i < rdos.length; i++)
{
rdos[i].indexs = i;
rdos[i].onchange = function ()
{
for ( var j = 0; j < rdos.length; j++)
{
if (j != this.indexs)
{
Yugi.setRadio (j, false);
}
}
Yugi.setRadio (this.indexs, this.checked);
};
}
for ( var i = 0; i < rdos.length; i++)
{
var flag = Yugi.getRadio (i);
if (flag == "true")
{
rdos[i].checked = true;
break;
}
}
};
</script>
</head>
<body>
<label><input type="radio" name="rdo" checked="checked" />one</label>
<label> <input type="radio" name="rdo" />two </label>
<label> <input type="radio" name="rdo" />three </label>
</body>
</html>
js自带的cookie
<html>
<head>
<meta charset="utf-8" />
<title>last</title>
<script type="text/javascript">
var Yugi =
{
supportSessionStorage : !!window.sessionStorage,
getRadio : function (name)
{
if (Yugi.supportSessionStorage)
{
return Yugi.readSessionStorage (name);
}
else
{
return Yugi.readCookie (name);
}
},
setRadio : function (name, value)
{
if (Yugi.supportSessionStorage)
{
Yugi.writeSessionStorage (name, value);
}
else
{
Yugi.writeCookie (name, value, 1);
}
},
writeSessionStorage : function (name, value)
{
window.sessionStorage.setItem (name, value);
},
readSessionStorage : function (name)
{
return window.sessionStorage.getItem (name);
},
writeCookie : function (name, value, hours)
{
var expire = "";
if (hours != null)
{
expire = new Date ((new Date ()).getTime () + hours * 3600000);
expire = "; expires=" + expire.toGMTString ();
}
document.cookie = name + "=" + escape (value) + expire;
},
readCookie : function (name)
{
var cookieValue = "";
var search = name + "=";
if (document.cookie.length > 0)
{
offset = document.cookie.indexOf (search);
if (offset != -1)
{
offset += search.length;
end = document.cookie.indexOf (";", offset);
if (end == -1)
end = document.cookie.length;
cookieValue = unescape (document.cookie.substring (offset, end))
}
}
return cookieValue;
}
};
window.onload = function ()
{
var rdos = document.getElementsByName ('rdo');
for ( var i = 0; i < rdos.length; i++)
{
rdos[i].indexs = i;
rdos[i].onchange = function ()
{
for ( var j = 0; j < rdos.length; j++)
{
if (j != this.indexs)
{
Yugi.setRadio (j, false);
}
}
Yugi.setRadio (this.indexs, this.checked);
};
}
for ( var i = 0; i < rdos.length; i++)
{
var flag = Yugi.getRadio (i);
if (flag == "true")
{
rdos[i].checked = true;
break;
}
}
};
</script>
</head>
<body>
<label><input type="radio" name="rdo" checked="checked" />one</label>
<label> <input type="radio" name="rdo" />two </label>
<label> <input type="radio" name="rdo" />three </label>
</body>
</html>
js自带的cookie
相关文章推荐
- JQuery1——基础($对象,选择器,对象转换)
- JavaScript演示排序算法
- 2015-2016网页设计趋势分析 Web Design of Trends
- jQuery Ajax 跨域调用
- 移动端的长按事件
- jquery教程靠边站,一分钱不花让你免费学会jquery
- JQuery+Strusts1.x无刷新登录
- $.ajax()方法详解
- jQuery ajax - ajax() 方法
- JavaScript 各种遍历方式详解
- 数组方法汇总
- cookie的secure属性详解
- 浏览器 cookie 限制
- jQuery Html控件基本操作(日常收集整理)
- jQuery插件实现文字无缝向上滚动效果代码
- jQuery菜单插件用法实例
- JQuery 初体验(建议学习jquery)
- 基于Jquery和CSS3制作数字时钟附源码下载(CSS3篇)
- Jquery实现的table最后一行添加样式的代码