作者ibmibmibm (根暗で陰湿?大きなお世話)
看板Web_Design
標題Re: [問題]新手 javascript的問題
時間Thu Oct 27 17:46:04 2005
<!DOCTYPE html PUBLIC
"-//W3C//DTD XHTML 1.0 Strict//EN"
"DTD/xhtml1-strict.dtd">
<html>
<head>
<title>樂透測試</title>
</head>
<body>
<script type="text/javascript">
var text1 = document.getElementById("text1");
function RandomInt( low, high )
{
return Math.floor(Math.random()*(high-low+1)) + low;
}
function lottery()
{
var i;
var pocket = [];
text1.value = "";
for(i = 0; i < 42; ++i)
pocket.push(i);
var hand = [];
for(i = 0; i < 6; ++i)
{
var choose = Randint(0, pocket.length);
hand.push(pocket[choose]);
pocket[choose] = pocket[pocket.length - 1];
pocket.pop();
}
text1.innerHTML = hand[0];
for(i = 1; i < hand.langth; ++i)
{
text1.innerHTML += ', ' + hand[i];
}
}
</script>
<div><span id="text1"></span><a href="javascript: lottery()">選號</a></div>
</body>
</html>
--
▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄ ▁ ▄-▄▄
██◤ ◥█◤ ██◣ ██◣ ██◤ ◢██ ▅▆◤ -▅▃
█ █ █ █ █▄▄ █ █ █ ◣ ◢ /▁ -
█ ◤ █ ██◢█ ▄▄▌█◢ █ █ ◤ ◥ ◤ ◢
█ ◢█◣ █ ◣ ██◤ █ ██◤ ◢▍
▃▃▃▃▃▃▃▃▃▃▃▃▃▃▃▃▃▃▃▃▃▃▃▃▃▃ ▊ Mozilla Firefox
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 140.122.126.43