开发者社区 问答 正文

随着时间后台数值添加的问题

我有一个页面,我想让它显示个每隔多少分钟就加一的数字,比如说现在我看这个数字是100,十分钟后就是101,再过5分钟就是102,并且不受访客和页面刷新影响。中间这个时间要在5分钟10分钟20分钟这三个内随机。不知怎么做到,asp、php、html、js、jq均可。随机做不到可以不做

展开
收起
小旋风柴进 2016-03-10 11:06:15 2004 分享 版权
1 条回答
写回答
取消 提交回答
  • var thisNum;//定义
    var timeArray=[5,10,20];//定义随机时间数组
    var timeT=timeArray[Math.round(Math.random()*2)]*60*1000;//随机取出一个值赋值给timeT
    function addNum(){
    if(window.localStorage.getItem('thisNum')!=''){
    thisNum=window.localStorage.getItem('thisNum');//获取本地的数据
    }else{
    thisNum=100;
    }
    thisNum+=1;
    window.localStorage.setItem('thisNum',thisNum);//设置本地的数据
    console.log(window.localStorage.getItem('thisNum'));
    setTimeout(addNum(),timeT);
    timeT=timeArray[Math.round(Math.random()*2)]*60*1000;
    }
    window.onload=addNum();
    2019-07-17 18:57:12
    赞同 展开评论
问答分类:
问答地址: