利用localStorage类为网页添加访问量统计

363 views

JS代码。

 

<script type=”text/javascript”>
if (localStorage.pagecount)
{
localStorage.pagecount=Number(localStorage.pagecount) +1;
}else{
localStorage.pagecount=1;
}
document.write(“访问数: ” + localStorage.pagecount + ” time(s).”);
//$(“#addtongji”).in=(“访问数: ” + localStorage.pagecount + ” time(s).”)
document.getElementById(‘addtongji’).innerHTML=”访问数: ” + localStorage.pagecount + ” time(s).”;

//var btn_input = document.getElementById(“addtongji”);
// btn_input.type=”text”;
// btn_input.value=”访问数: ” + localStorage.pagecount + “次”

</script>

然后在html中加<div id=”addtongji”></div>

如果想加在动态文本框上,代码换一下。

<script type=”text/javascript”>
if (localStorage.pagecount)
{
localStorage.pagecount=Number(localStorage.pagecount) +1;
}else{
localStorage.pagecount=1;
}
document.write(“访问数: ” + localStorage.pagecount + ” time(s).”);
//$(“#addtongji”).in=(“访问数: ” + localStorage.pagecount + ” time(s).”)
document.getElementById(‘addtongji’).innerHTML=”访问数: ” + localStorage.pagecount + ” time(s).”;

var btn_input = document.getElementById(“addtongji”);
btn_input.type=”text”;
btn_input.value=”访问数: ” + localStorage.pagecount + “次”

</script>

HTML中添加

<input type=”text” id=”addtongji”>

如果您觉得这篇文章对您有帮助,欢迎继续关注本站!!!我要赞助本站>>>

Leave a Reply

电子邮件地址不会被公开。 必填项已用*标注