-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathex-059.html
More file actions
75 lines (60 loc) · 1.56 KB
/
ex-059.html
File metadata and controls
75 lines (60 loc) · 1.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>五倍樂透自動選號機</title>
<style type="text/css">
.wrap{
padding: 1em;
}
.lottery-nums{
overflow: hidden;
width: 600px;
}
.lottery-nums > div{
display: block; float: left;
width: 25px; height: 25px;
border: 1px solid #999;
background-color: #fff;
color: #555;
font-size: 20px;
padding: 10px;
text-align: center;
line-height: 25px;
margin-right: 10px;
margin-bottom: 10px;
}
.lottery-nums .highlight{
background-color: red;
color: #fff;
}
</style>
</head>
<body>
<div class="wrap">
<div class="lottery-nums"></div>
<div class="lottery-result">開獎號碼: <span></span></div>
</div>
<script src="scripts/jquery-3.1.0.js"></script>
<script type="text/javascript">
var lottery = [], number, n;
while( lottery.length < 6 ){
number = parseInt( Math.random() * 49 + 1, 10 );
if( lottery.indexOf( number ) === -1 ){
lottery.push( number );
}
}
console.log( 'lottery: ', lottery );
// 產生 49 顆按鈕
for( var i = 1; i < 50; i++ ){
$('.lottery-nums').append('<div>' + i + '</div>');
}
// 1. 把號碼列出至 .lottery-result > span 中。
$('.lottery-result > span').append('<div>' + lottery + '</div>');
// 2. 把被選中的號碼加入 highlight class
for( var i = 0; i < 6; i++ ){
$('.lottery-nums div').eq(lottery[i]-1).addClass('highlight');
}
</script>
</body>
</html>