本帖最后由 qymdf4 于 2010-07-24 17:28:24 编辑

解决方案 »

  1.   


    <script>   
    var theTimer;   
    var iNum=0;   
           
    function checkLoad() {   
        iNum=selectFrom(0,9); 
        document.getElementById("stext").innerHTML=iNum;   
        theTimer = setTimeout("checkLoad()", 8); 
    }   
    function selectFrom(iFirstValue,iLastValue){   
        var iChoices =  iLastValue-iFirstValue+1;   
        return Math.floor(Math.random()*iChoices+iFirstValue);   
    }   
      
    function stopPlay(iNum) {   
        clearTimeout(theTimer);
    }   
     
    function getDia() {
    alert(document.getElementById("stext").innerHTML)

    </script>   
    <body>   
    <table width="100%">   
    <tr height="300">   
    <td align="center">   
    <div id="stext" style="font-size:146px;color:red;bold" align="center">0</div>   
    </td>   
    </tr>   
    <tr height=""><td>   
    <div align="center">   
    <input type="button" value="开始" onClick="checkLoad(),setTimeout('stopPlay()',1000)" style="height:60;width:130"/>  
    <input type="button" value="获取" onClick="getDia()" style="height:60;width:130"/>   
    </div>   
    </td>   
    </tr>   </table>
      

  2.   


    <script>   
    var theTimer;   
    var iNum=0;   
           
    function checkLoad() {   
        iNum=selectFrom(0,9); 
        document.getElementById("stext").innerHTML=iNum;   
        theTimer = setTimeout("checkLoad()", 8); 
    }   
    function selectFrom(iFirstValue,iLastValue){   
        var iChoices =  iLastValue-iFirstValue+1;   
        return Math.floor(Math.random()*iChoices+iFirstValue);   
    }   
      
    function stopPlay(iNum) {   
        clearTimeout(theTimer);
        alert("抽奖结果为:"+document.getElementById("stext").innerHTML);
    }   
    </script>   
    <body>   
    <table width="100%">   
    <tr height="300">   
    <td align="center">   
    <div id="stext" style="font-size:146px;color:red;bold" align="center">0</div>   
    </td>   
    </tr>   
    <tr height=""><td>   
    <div align="center">   
    <input type="button" value="开始" onClick="checkLoad(),setTimeout('stopPlay()',1000)" style="height:60;width:130"/>    
    </div>   
    </td>   
    </tr>   </table>