亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

基于javascript實現(xiàn)彩票隨機數(shù)生成(簡單版)

 更新時間:2020年04月17日 16:23:44   作者:Cakty、Riven  
這篇文章主要介紹了基于javascript實現(xiàn)彩票隨機數(shù)生成的相關資料,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下

本文實例講解了JavaScript 實現(xiàn)彩票中隨機數(shù)組的獲取詳細代碼,分享給大家供大家參考,具體內(nèi)容如下

效果圖:

具體代碼:

<!DOCTYPE html>
<html lang="en">
<head>
 <meta charset="UTF-8">
 <title>Math.random方法彩票隨機數(shù)的生成</title>
</head>
<body>
 <!-- 設置樣式 -->
 <input type="text" id="text">
 <button id="btnGo">開始</button>
 <button id="btnStop">獲取隨機數(shù)組</button>

 <script type="text/javascript">

 //獲取節(jié)點
 var btnGo = document.getElementById("btnGo");
 var btnStop = document.getElementById("btnStop");
 var text = document.getElementById("text");
 //定義生成最小到最大值的隨機函數(shù)
 function rand(min,max){
  return parseInt(Math.random()*( max - min + 1) + min);
 }
 
 function start(min,max,length){
  //定義空數(shù)組
  var arr = [];

  while(arr.length<length){
   //生成一個隨機數(shù)prem
  var prem=rand(min,max);
  //判斷生成的隨機數(shù)prem是否在數(shù)組arr里,果然不在,就將這個隨機數(shù)插入到數(shù)組里,如果在,執(zhí)行下一次循環(huán)
  if(arr.indexOf(prem) == -1){

   arr.push(prem);
  }
  }
  //返回數(shù)組arr
  return arr;
 }

 var timer = 0;
 //單擊開始按鈕生成隨機數(shù)組
 btnGo.onclick =function(){
  //清除
  clearInterval(timer);
  timer = setInterval(function() {
  text.value = start(1,33,7);
 },50)
 }
 //單擊停止按鈕獲取一組隨機數(shù)
 btnStop.onclick =function(){
  clearInterval(timer);
 }
 
 </script>
</body>
</html>

以上就是本文的詳細內(nèi)容,希望對大家的學習javascript程序設計有所幫助。

相關文章

最新評論