js cookies 간단 한 통계 방문 횟수 실현

1109 단어 jscookies통계

<script type="text/javascript">
if(getCookie("num")){
var nn=parseInt(getCookie("num"));
setCookie("num",++nn);
}else{
setCookie("num",1);
}
function getCookie(name){
var str=document.cookie.split(";");
for(i=0;i<str.length;i++){
var str2=str[i].split("=")
if(str2[0].replace(/\s(.*)\s/,"$1")==name){
return str2[1];
}
}
}
function setCookie(name,value){
var Days=30;
var exp = new Date();
exp.setTime(exp.getTime() + Days*24*60*60*1000);
document.cookie = name + "="+ escape(value) +";expires"+ exp.toGMTString();
}
alert(" "+getCookie("num")+" ");

/*String.prototype.Trim=function(){
return this.replace(/\s(.*)\s/,"$1");
}
String.prototype.alert2=function(str){
alert(" alert2!!! :"+str);
}
var aa="";
aa.alert("liugang");*/
</script>

좋은 웹페이지 즐겨찾기