zoukankan      html  css  js  c++  java
  • javascript学习笔记:随机数统计

     1<div id="div1"></div>
     2<div id="div2"></div>
     3
     4<script>
     5function write1(){
     6    var i = 0;
     7    for(i=0;i<10;i++){
     8        document.getElementById("div1").innerHTML += Math.ceil(Math.random()*10)+";";
     9        }

    10    
    11   // setTimeout("write1()",100);
    12}

    13
    14function count1(){
    15    var testArr = document.getElementById("div1").innerHTML.split(";")
    16    var arrLth = testArr.length;
    17    var textStr="";
    18    var count1=0,count2=0,count3=0,count4=0,count5=0,count6=0,count7=0,count8=0,count9=0,count10=0;
    19    for(i=0;i<=arrLth-1;i++){
    20        switch(eval(testArr[i])){
    21        case 1:count1+=1;
    22               break;
    23        case 2:count2+=1;
    24               break;
    25        case 3:count3+=1;
    26               break;
    27        case 4:count4+=1;
    28               break;
    29        case 5:count5+=1;
    30               break;
    31        case 6:count6+=1;
    32               break;
    33        case 7:count7+=1;
    34               break;
    35        case 8:count8+=1;
    36               break;
    37        case 9:count9+=1;
    38               break;
    39        case 10:count10+=1;
    40               break;
    41        }

    42       
    43    }

    44     
    45   
    46    for(i=1;i<=10;i++){
    47       textStr+=  "count"+i+"的值为:"+eval("count"+i)+"</br>";
    48    }

    49    document.getElementById("div2").innerHTML =textStr;
    50
    51}

    52</script>
    53
    54
    55<input id="Button1" type="button" value="button" onclick="write1()" />
    56<input id="Button2" type="button" value="统计" onclick="count1()" />
  • 相关阅读:
    2012年浙大:Hello World for U
    noip2011普及组:统计单词
    noip2013提高组:积木大赛
    蓝桥杯:错误票据
    C#知识点
    疑问
    C#多态
    SQLServer导入Excel,复杂操作
    SQLServer数据库基本操作,导入Excel数据
    C#基础学习
  • 原文地址:https://www.cnblogs.com/8586/p/1239022.html
Copyright © 2011-2022 走看看