1-20之间随机生成数字,不断的在页面上进行滚动显示
然后按停止,就停止,比如停止在15
然后再按开始就再抽,但是不能再抽到15了,就在1-14,16-20中进行抽取应该怎么做,着急

解决方案 »

  1.   


    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>抽签程序</title>
    <style type="text/css">
    html, body{
    padding:0px; margin:0px; font-size:12px;
    }
    body{
    margin:50px;
    }
    #result{
    height:20px; margin-bottom:10px;
    }
    #result div{
    float:left; border:1px solid #006699; color:#c00; width:24px; height:20px; line-height:20px;
    margin-right:15px; text-align:center;
    }
    #control div{
    float:left; width:24px; height:20px; line-height:20px; border:1px solid #008800; color:#c00;
    margin-right:20px; text-align:center;
    }
    </style>
    <script type="text/javascript">
    var arrData = [], timerID = 0;
    for(var i = 1; i <=20; i++){
    arrData[i - 1] = i;
    }
    function $(id){
    return document.getElementById(id);
    }
    function Start(btn){
    if(timerID > 0){
    clearInterval(timerID);
    timerID = 0;
    }
    if(arrData.length < 1){
    alert("没有数据了!");
    return;
    }
    if(btn.value == "开始"){
    timerID = setInterval(function(){
    $("num").index = parseInt(Math.random() * (arrData.length - 1));
    $("num").innerHTML = arrData[$("num").index];
    }, 30);
    btn.value = "暂停";
    }else{
    var div = document.createElement("div");
    div.innerHTML = $("num").innerHTML;
    $("result").appendChild(div);
    arrData.splice($("num").index, 1);
    btn.value = "开始";
    }
    }
    window.onload = function(){
    $("btnStart").focus();
    };
    </script>
    </head><body>
    <div id="result"></div><div style="clear:both; float:none"></div>
    <div id="control">
    <div id="num">0</div>
        <input type="button" id="btnStart" value="开始" onclick="Start(this)" />
    </div>
    </body>
    </html>
      

  2.   


    有个地方没搞好:
    $("num").index = parseInt(Math.random() * (arrData.length - 1));
    改成
    $("num").index = parseInt(Math.random() * (arrData.length));
      

  3.   


    <html>
    <head>
    <title>身份证号是否有效验证 </title>
    <script>
    var old = new Array();
    function getm()
    {
    return parseInt(Math.random()*(21-1)+1);
    }
    var newm;
    function getMM()
    {
    newm = getm();
    if(old.length==0)
    {
    old.push(newm);
    return newm;
    }
    if(old.length>=20)
    {
    return '抽完了';
    }
    for(var i=0,len=old.length;i<len;i++)
    {
    if(old[i]==newm)
    {
    return getMM();
    }
    }
    old.push(newm);
    return newm;
    }
    </script>
    </head>
    <body>
    <input type="button" value="抽" onclick="alert(getMM())"/>
    </body>
    </html> 
      

  4.   


        <div id="div1"></div>
        <input id="cmdStart" type="button" value="开始"  />
        <input id="cmdStop" type="button" value="停止" />     var timeHandle, data, index;
         function cq() {
             data = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20];
             index = Math.round(Math.random() * 19);
             document.getElementById('div1').innerHTML = data[index];
             timeHandle = setTimeout(cq, 500);
         }
         document.getElementById('cmdStart').onclick = function() {
             if(data.length == 0) {
                 alert('没有数据了!');
                 return;
             }
             timeHandle = setTimeout(cq, 500);
         }
         document.getElementById('cmdStop').onclick = function() {
             clearTimeout(timeHandle);
             data.splice(index, 1);
         }
      

  5.   


    数组是从0开始索引的,data[19] = 20 啊