码迷,mamicode.com
首页 > Web开发 > 详细

js cookie的封装和调用

时间:2016-10-05 15:22:09      阅读:145      评论:0      收藏:0      [点我收藏+]

标签:

<script>
function setCookie(cname,cvalue,exdays){
var d = new Date();
d.setTime(d.getTime()+(exdays*24*60*60*1000));
var expires = "expires="+d.toGMTString();
document.cookie = cname+"="+cvalue+"; "+expires;
}
function getCookie(cname){
var name = cname + "=";
var ca = document.cookie.split(‘;‘);
for(var i=0; i<ca.length; i++) {
var c = ca[i].trim();
if (c.indexOf(name)==0) return c.substring(name.length,c.length);
}
return "";
}
function checkCookie(){
var telephone=getCookie("telephone");
if (telephone!=""){
alert("Welcome again " + telephone);
}
else {
telephone = $("#telephone").val();
if (telephone!="" && telephone!=null){
setCookie("telephone",telephone,60);
}
}
}
</script>

js cookie的封装和调用

标签:

原文地址:http://www.cnblogs.com/freddyhuang/p/5932123.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!