-
Notifications
You must be signed in to change notification settings - Fork 7
/
index.html
137 lines (123 loc) · 4.09 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
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>表单联动</title>
<style>
* {
margin: 0;
padding: 0;
}
#content {
width: 500px;
height: 150px;
margin: 0 auto;
background-color: #9acfea;
text-align: center;
}
.rad-wrap label {
display: inline-block;
width: 150px;
text-align: center;
margin: 20px 0;
}
.rad-wrap input[type='radio'] {
width: 15px;
height: 15px;
border-radius: 50%;
cursor: pointer;
}
.sch-info select {
width: 200px;
height: 30px;
margin: 0 10px;
border-radius: 4px;
}
.ntsch-info #work-in {
width: 300px;
height: 30px;
margin-left: 20px;
border-radius: 2px;
border: none;
}
.ntsch-info {
display: none;
}
</style>
</head>
<body>
<div id="content">
<form action="#">
<div class="rad-wrap">
<label for="in-school"><input type="radio" id="in-school" name="person" checked>在校生</label>
<label for="nt-school"><input type="radio" id="nt-school" name="person">非在校生</label>
</div>
<div class="sch-info">
<label for="city">学校
<select id="city" onchange="showSch(this)">
<option selected>=请选择=</option>
</select>
<select id="sch">
<option>=请选择=</option>
</select>
</label>
</div>
<div class="ntsch-info">
<label for="work-in">就业单位 <input type="text" id="work-in"></label>
</div>
</form>
</div>
<script>
var inSchool = document.getElementById('in-school');
var ntSchool = document.getElementById('nt-school');
var city = document.getElementById('city');
var sch = document.getElementById('sch');
var schInfo = document.getElementsByClassName('sch-info')[0];
var ntschInfo = document.getElementsByClassName('ntsch-info')[0];
var cityArr = ['北京', '南京', '南昌', '广州', '深圳'];
var schArr = [
['北京大学', '清华大学', '北京理工大学', '中国人民大学', '北京师范大学', '北京航空航天大学', '北京科技大学', '北京交通大学'],
['南京大学', '东南大学', '河海大学', '南京农业大学', '南京邮电大学'],
['南昌大学', '江西师范大学', '江西财经大学', '南昌航空大学', '江西理工大学'],
['中山大学', '华南理工大学', '暨南大学', '华南师范大学', '广州大学'],
['深圳大学', '南方科技大学']
];
/*radio切换事件*/
function changePlay(radio, nod) {
radio.style.display = 'block';
nod.style.display = 'none';
}
inSchool.onclick = function () {
changePlay(schInfo, ntschInfo);
};
ntSchool.onclick = function () {
changePlay(ntschInfo, schInfo);
};
/*动态添加城市*/
(function addCity() {
for (var i = 0; i < cityArr.length; i++) {
var cityOption = document.createElement('option');
cityOption.innerText = cityArr[i];
cityOption.value = i;
city.appendChild(cityOption);
}
})();
/*city的onchange事件*/
function showSch(obj) {
var val = obj.options[obj.options.selectedIndex].value;
if (val != null) {
sch.options.length = 1;
addSch(val)
}
}
/*显示学校*/
function addSch(i) {
for (var j = 0; j < schArr[i].length; j++) {
var schOption = document.createElement('option');
schOption.innerText = schArr[i][j];
sch.appendChild(schOption);
}
}
</script>
</body>
</html>