Re: [問題]新手 javascript的問題
<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)
討論串 (同標題文章)
完整討論串 (本文為第 1 之 2 篇):
Web_Design 近期熱門文章
PTT數位生活區 即時熱門文章