郑德才博客 记录学习,记录工作,学习知识分享!

使用jquery和txt文件对Asp页面进行统计,增长数量自定义

建立asp页面,在此之前要有一个txt文件,里面存放的是统计的数值,这个当然可以随意更改,统计的值也就随之改,里面的代码如下:

<%    
response.write counter()
function counter()
whichfile=server.mappath("n.txt")
'打开文件并将其值读取,最后关闭连接释放资源
set fso=createobject("Scripting.FileSystemObject")
set openfile=fso.opentextfile(whichfile,1)
visitors=openfile.readline
openfile.close
'页面显示记数内容并做加1运算
visitors=visitors+RndNumber(1,1)
'将新的数值添加写入到文本,最后关闭所有连接释放资源
set creatfile=fso.createtextfile(whichfile)
creatfile.writeLine(visitors)
creatfile.close
set fso=nothing
counter=visitors
end function 
'自定义函数
'1-3之间的随机数
Function RndNumber(MaxNum,MinNum)
 Randomize 
 RndNumber=int((MaxNum-MinNum+1)*rnd+MinNum)
 RndNumber=RndNumber
End Function

%>

html页面中使用jquery进行统计,并显示到span标签中,记得添加jquery包,代码如下:

<script type="text/javascript">
    function load() {

        $.ajax({
            type: "POST",
            url: "number.asp",
            timeout: 1000,
            error: function() {},
            success: function(msg) {
                $("#count").html(msg); //span的标记编号id值
            }
        });
    }

    load();
</script>

2013年5月30日 | 发布:郑德才博客 | 分类:学习之路 | 评论:0

发表留言: