-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
80 lines (76 loc) · 2.32 KB
/
index.html
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
76
77
78
79
80
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>猜数字游戏</title>
<style type="text/css">
.main {
position: relative;
left: 500px;
top: 200px;
width: 400px;
height: 400px;
background: lightgreen;
border-radius: 50%;
}
.main p {
display: block;
position: relative;
left: 110px;
top: 150px;
font-size: 24px;
font-family: "方正喵呜体";
color: green;
}
#text {
display: block;
position: relative;
left: 122px;
top: 180px;
padding-left: 45px;
width: 80px;
height: 80px;
border: 3px yellow solid;
border-radius: 40%;
background: lightgreen;
}
#button {
position: relative;
top: 210px;
left: 170px;
}
</style>
</head>
<body>
<div class="main">
<p>猜一个数字吧</p>
<input type="text" id="text" value="">
<input type="button" id="button" value="提交">
</div>
<script type="text/javascript">
var num = Math.floor(Math.random()*1000+1);
var patt = /^(?!00)(?:[0-9]{1,3}|1000)$/;
var rendom ="1-1000";
var id = "text";
console.log("哈哈你很聪明哟,知道打开控制台,要猜的数字是"+num);
function numberRiddle () {
var text = parseInt(document.getElementById(id).value);
if (num == ''||patt.test(text)==false) {
alert("请输入"+rendom+"的数字");
}
else {
if (num>text) {
alert("你猜小了,大胆一点吧");
}else if(num<text) {
alert("你猜大了,人家很腼腆的");
}else {
alert("你猜对了,不过没什么奖励");
}
}
}
window.onload = function() {
document.getElementsByTagName('input')[1].addEventListener("click",numberRiddle,false);
}
</script>
</body>
</html>