1.Html5 提供两种客户端存储数据的新方法,一种是没有时间限制的localStorage,另一种是针对一个Session的数据存储sessionStorage。下面是利用localStorage实现的统计网页访问量的方法:
function(){
if(localStorage.visitCount){
//javascript中实现自增先要将变量用Number方法转换为整型,否则+作为连接字符串操作符会将1当作字符串与原字符串连接起来。
localStorage.visitCount = Number(localStorage.visitCount) +1;}else{
localStorage.visitCount = 1;
}
document.write('Visites '+localStorage.visitCount+' times.');
}
本文介绍如何利用HTML5的localStorage方法来统计网页的访问量,并通过JavaScript实现自增功能。

被折叠的 条评论
为什么被折叠?



