作者Tachi (下象棋)
看板Web_Design
標題Re: [問題]新手 javascript的問題
時間Wed Oct 26 00:58:33 2005
<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)