この記事では、JSによる単純なランダム宝くじを実装する方法について説明します。参照のためにそれを共有してください。特定の実装方法は次のとおりです。
コードコピーは次のとおりです。
<html>
<Title> JSランダム宝くじプログラム</title>
<head> <Meta http-equiv = content-type content = "text/html; charset = gb2312">
</head>
<body>
<script type = "text/javascript">
var alldata = "a、b、c、d、e、f、g、h、i、j、k"
var alldataarr = alldata.split( "、");
var num = alldataarr.length-1;
varタイマー
関数変化()
{
document.getElementById( "oknum")。innerhtml = alldataarr [getrnd(0、num)];
}
function start(){
ClearInterval(タイマー);
Timer = setInterval( 'Change()'、100);
}
function ok(){
ClearInterval(タイマー);
document.getElementById( "showresult")。value = document.getElementById( "oknum")。innertext;
}
関数getrnd(min、max){
return parseint(math.random()*(max-min+1));
}
</script>
<center>
<div id = "oknum" name = "oknum"> [start] </div>をクリックしてください
<button onclick = "start()" accesskey = "s"> start </button>
<button onclick = "ok()" accesskey = "o"> stop </button>
あなたの選択は次のとおりです:
<input type = "text" id = "showresult" value = "">
</center>
</body>
</html>
この記事がみんなのJavaScriptプログラミングに役立つことを願っています。