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