-
Notifications
You must be signed in to change notification settings - Fork 0
/
0914-練習6-下拉式選單連動.html
77 lines (60 loc) · 2.27 KB
/
0914-練習6-下拉式選單連動.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>select option change</title>
<script src="https://code.jquery.com/jquery-3.5.1.js"
integrity="sha256-QWo7LDvxbWT2tbbQ97B53yJnYU3WhH/C8ycbRAkjPDc=" crossorigin="anonymous"></script>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css"
integrity="sha384-JcKb8q3iqJ61gNV9KGb8thSsNjpSL0n8PARn9HuZOnIxN0hoP+VmmDGMN5t9UJ0Z" crossorigin="anonymous">
</script>
<style>
</style>
</head>
<body>
<div class="container mt-5">
<div class="row"></div>
<form action="">
<div class="form-row">
<div class="form-group">
<select name="city" id="city" class="form-control">
<option value="0">基隆</option>
<option value="1">台北</option>
<option value="2">新北</option>
</select>
</div>
<div class="form-group">
<select name="district" id="district" class="form-control">
<option value="0">七堵</option>
<option value="1">中正</option>
<option value="2">暖暖</option>
</select>
</div>
</div>
</form>
</div>
<script>
let districtObj = [
["七堵", "中正", "暖暖"],
["中正", "大安", "信義"],
["蘆洲", "三重", "新店"],
];
// 用for迴圈
// $("#city").change(function () {
// let cityIndex = $(this).val();
// // console.log("hi", $(this).val());
// for (let i = 0; i < 3; i++) {
// $("#district option").eq(i).text(districtObj[cityIndex][i]);
// }
// });
// 用.each()
// $("#city").change(function () {
// const city_index = $(this).val();
// $("#district option").each(function(){
// $(this).text(districtObj[city_index][$(this).val()]);
// })
// });
</script>
</body>
</html>