Re: [問題]新手 javascript的問題

看板Web_Design作者 (下象棋)時間19年前 (2005/10/26 00:57), 編輯推噓0(000)
留言0則, 0人參與, 最新討論串1/2 (看更多)
<head> <script language = javascript> function RandomInt( low, high ) { return Math.floor(Math.random()*(high-low+1)) + low; } function lotor() { var tmp= []; text1.value = ""; outer_loop: for( n = 0; n < 6; n++){ tmp[n] = RandomInt(1,42); for( i = 0 ; i < n ; i++){ if (n != i && tmp[n] == tmp[i]){ break outer_loop; } } text1.value += (tmp[n] + " ,"); } if (n != 6) lotor(); } </script> </head> <body> <input type = text name = text1 ><br><br> <input type = button name = button1 value = "選號" OnClick = "lotor();"> <br><br> </body> </html> 或不要加break的改這樣 function lotor() { var tmp= []; for( n = 0; n < 6; n++){ tmp[n] = RandomInt(1,42); for( i = 0 ; i < n ; i++){ if (n != i && tmp[n] == tmp[i]){ n--; } } } text1.value = (tmp[0]+" ,"+tmp[1]+" ,"+tmp[2]+" ," +tmp[3]+" ,"+tmp[4]+" ,"+tmp[5]); } -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 211.74.10.228 ※ 編輯: Tachi 來自: 211.74.10.228 (10/26 06:54)
文章代碼(AID): #13NcG2e6 (Web_Design)
文章代碼(AID): #13NcG2e6 (Web_Design)