zoukankan      html  css  js  c++  java
  • 简单的随机数实现

    <div class="sjs_btn">当前查看文章的人数:<span id="cont-link">56</span></div>
    <style>
    <!--
    .sjs_btn{margin-left: auto; margin-right: auto; padding:10px 20px; font-size: 22px;line-height: 1.0; color: #fff; background: #349de6;}
    -->
    </style>
    <script type="text/javascript">
    <!--
    (function(){
        function GetRandomNum(Min,Max){   
            var Range = Max - Min;   
            var Rand = Math.random();   
            return(Min + Math.round(Rand * Range));   
        }   
        // 在线数
        var swtNo = document.getElementById("cont-link");
        var timer1 = setInterval(showSwt,2000);
        function showSwt(){
            timer1 ++;
            var swtnum = GetRandomNum(8,99);
            swtNo.innerHTML = swtnum;
            if(timer1 > 500){
                clearInterval(timer1);
            }    
        }
    })();
    -->
    </script>

    近来有个需求需要用到数量的自动变化,但是又不是严格要求数量依附于某些数据增减。故临时使用随机数的方式实现

    首先先贴上代码

    接下来就是demo:

    当前查看文章的人数:56
  • 相关阅读:
    eclipse中在线添加TestNG插件步骤(需联网)
    [IOI2008] Type Printer 打印机
    P2765 魔术球问题
    [HNOI2004]敲砖块
    P3931 SAC E#1
    [WC2005]友好的生物
    P1357 花园
    [SDOI2016]征途
    [APIO2014]序列分割
    [HNOI2008]玩具装箱TOY
  • 原文地址:https://www.cnblogs.com/zoomingos/p/8492299.html
Copyright © 2011-2022 走看看