-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgetAnswer_2.html
182 lines (153 loc) · 6.19 KB
/
getAnswer_2.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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<link rel="stylesheet" type="text/css" href="css/newStyle.css">
<link rel="stylesheet" type="text/css" href="css/nav.css">
<link rel="stylesheet" type="text/css" href="css/new_main.css">
<link rel="icon" href="img/logo_1.png" type="image/x-icon">
<link rel="shortcut icon" href="img/logo_1.png" type="image/x-icon">
<script async defer data-website-id="0a453f1f-f1bc-4f69-9772-6a1e6cfea828" src="https://stat.buctsnc.cn/umami.js" data-domains="https://arg2022.buctsnc.cn/" data-cache="true"></script>
<title>Day 2</title>
</head>
<script src="./js/jquery.js"></script>
<body>
<header id="nav" style="display: flex;flex-direction: column">
<div>
<img class="logo" src="img/buctlogo.png" alt="logo">
<img class="logo" src="img/snclogo.png" alt="logo">
</div>
</header>
<div class="answer_div" id="submit_form" style="display: none">
<form name="answer_form" method="post" class="answer_form" onsubmit="checkSubmit()">
<div class="alter_question" id="alter">
<div id="unselected_button"><button class="unselect" type="button" onclick="alter()">第一题</button></div>
<div id="selected_button"><button class="select" type="button" onclick="">第二题</button></div>
</div>
<table>
<tr>
<td>用户名:</td>
<td><input id="nickname" name="nickname" type="text" placeholder="注册过用户名" autocomplete="off" class="text_area"></td>
<td>没有注册?<a href="register.html">注册</a></td>
</tr>
<tr>
<td>电话号码:</td>
<td><input id="contact" name="contact" type="text" placeholder="注册过的电话号码" autocomplete="off" class="text_area"></td>
<td></td>
</tr>
<tr>
<td>获得的答案:</td>
<td><input id="answer_q2_2" name="answer_q2_2" type="text" placeholder="Day 2 第二题答案" autocomplete="off" class="text_area"></td>
<td></td>
</tr>
</table>
<div class="get_answer_button">
<button class="gab" type="reset" onclick="">重新输入</button>
<button class="gab" type="button" onclick="submits()">提交答案</button>
</div>
</form>
</div>
<div class="answer_div" id="goToPC" style="display: none; font-size: 14px;">
<div style="display: flex; flex-direction: column; height: 175px; width: 175px; background: rgba(0,0, 0, 0.70); justify-content:center;align-items: center; border-radius: 25px">
<img src="img/goToPC.png" alt="" style="height: 50px;width:50px;background: none;margin-bottom: 20px">
<p style="background: none">在PC端访问</p>
<p style="background: none">体验效果更佳</p>
</div>
</div>
</body>
<script>
window.onload = function() {
$("#nav").fadeIn();
$("#submit_form").fadeIn();
let flag = checkDevice();
if (flag == false) {
$("#goToPC").fadeIn();
setInterval(function() {
$("#goToPC").fadeOut();
}, 1000)
}
}
function checkDevice() {
let usrAgentInfo = navigator.userAgent;
let Agents = ['Android', 'iPhone', 'Windows Phone', 'iPad'];
let flag = true;
for (let i = 0; i < Agents.length; i++) {
if (usrAgentInfo.indexOf(Agents[i]) > 0) {
flag = false;
break;
}
}
return flag;
}
let submit = false;
function checkSubmit() {
if(!submit) {
// 表单提交后设置标志位
submit = true;
return true;
}
// 表单已经提交,不允许再次提交
console.log("请不要重复提交表单!");
return false;
}
function isLegalName (str) {
let re = /^[0-9a-zA-Z]*$/;
if (!re.test(str) || str.indexOf(" ") != -1) {
return false;
} else {
return true;
}
}
function isLegalTel(str) {
let re = /^[0-9|+]*$/;
if (!re.test(str) || str.indexOf(" ") != -1) {
return false;
} else {
return true;
}
}
function check(nickname, contact, answer_q2_2) {
if(nickname.length < 1 || contact.length < 10 || answer_q2_2.length < 1){
return false;
}
return true;
}
function submits() {
let nickname = document.getElementById("nickname")
let contact = document.getElementById("contact")
let answer_q2_2 = document.getElementById("answer_q2_2")
umami.trackEvent('submited answer day02_2', 'answer');
if(check(nickname.value, contact.value, answer_q2_2.value) && isLegalName(nickname.value) && isLegalTel(contact.value)){
$.ajax({
url:"https://sncdeveloper.cn:8000/argProject/day02_02",
method:"post",
async:"false",
data:{"nickname":nickname.value,"contact":contact.value,"answer_q2_2":answer_q2_2.value},
dataType:"json",
contentType:"application/x-www-form-urlencoded",
success(result){
nickname.value = ""
contact.value = ""
answer_q2_2.value = ""
window.alert(result.msg)
// if(result.data.solveStatus==1){
//
// }
},
error(msg){
console.log("error"+msg)
window.alert("活动太火爆了,请稍后再试")
}
})
}else{
if (!isLegalName(nickname.value))
alert("用户名只能由数字和字母组成!");
else
alert("联系方式格式有误或答案为空,请重新输入")
}
}
function alter() {
window.location.href = "getAnswer_1.html";
}
</script>
</html>