บทความนี้อธิบายวิธีการใช้ลอตเตอรีแบบสุ่มอย่างง่ายโดย 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, h, i, j, k"
var alldataarr = alldata.split (",");
var num = alldataarr.length-1;
ตัวจับเวลา var
การเปลี่ยนแปลงฟังก์ชั่น ()
-
document.getElementById ("oknum"). innerhtml = alldataarr [getrnd (0, num)];
-
ฟังก์ชั่นเริ่มต้น () {
ClearInterval (ตัวจับเวลา);
timer = setInterval ('เปลี่ยน ()', 100);
-
ฟังก์ชั่นตกลง () {
ClearInterval (ตัวจับเวลา);
document.getElementById ("showresult"). value = document.getElementById ("oknum"). innerText;
-
ฟังก์ชั่น getRnd (min, max) {
ส่งคืน parseint (math.random ()*(Max-min+1));
-
</script>
<enter>
<div id = "oknum" name = "oknum"> กรุณาคลิกเริ่ม </div>
<ปุ่ม onclick = "start ()" accesskey = "s"> เริ่ม </button>
<ปุ่ม onclick = "ตกลง ()" accessKey = "o"> หยุด </ Button>
ทางเลือกของคุณคือ:
<input type = "text" id = "showresult" value = "">
</enter>
</body>
</html>
ฉันหวังว่าบทความนี้จะเป็นประโยชน์กับการเขียนโปรแกรม JavaScript ของทุกคน