質問編集履歴
1
追記
title
CHANGED
File without changes
|
body
CHANGED
@@ -7,30 +7,133 @@
|
|
7
7
|
|
8
8
|
```Js
|
9
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
|
-
|
10
|
+
<!DOCTYPE html>
|
11
|
+
<html lang="ja">
|
12
|
+
<meta charset="utf-8" />
|
13
|
+
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
|
14
|
+
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
15
|
+
<head>
|
16
|
+
<title>最終課題</title>
|
17
|
+
<link
|
18
|
+
href="./bootstrap-4.4.1-dist/css/bootstrap.min.css"
|
19
|
+
rel="stylesheet"
|
20
|
+
/>
|
21
|
+
<script src="./jquery-3.4.1.min.js"></script>
|
22
|
+
<script src="./bootstrap-4.4.1-dist/js/bootstrap.min.js"></script>
|
23
|
+
<script>
|
24
|
+
$(function() {
|
25
|
+
const url =
|
26
|
+
"http://api.openweathermap.org/data/2.5/forecast?id=1849814&APPID=";
|
27
|
+
const key = "a362e731b66c5036016466ff86f756e4";
|
28
|
+
|
29
|
+
var position;
|
30
|
+
$.getJSON(url + key, function(json) {
|
31
|
+
$("#place").append("<h2>" + json.city.name + "</h3>");
|
32
|
+
for (var i = 0; i < json.list.length; i++) {
|
33
|
+
var tenki = "";
|
34
|
+
var date = json.list[i].dt_txt;
|
35
|
+
|
36
|
+
var year = Number(date.substr(0, 4));
|
37
|
+
// console.log(date);
|
38
|
+
// console.log(year);
|
39
|
+
var month = Number(date.substr(5, 2));
|
40
|
+
// console.log(month);
|
41
|
+
var day = Number(date.substr(8, 2));
|
42
|
+
// console.log(day);
|
43
|
+
var hour = Number(date.substr(11, 2));
|
44
|
+
// console.log(hour);
|
45
|
+
// 2020-01-18 21:00:00
|
46
|
+
|
47
|
+
hour += 9;
|
48
|
+
|
49
|
+
if (hour > 24) {
|
50
|
+
hour -= 24;
|
51
|
+
day += 1;
|
52
|
+
if (
|
53
|
+
(day > 31 && month == 1, 3, 5, 7, 8, 10, 12) ||
|
54
|
+
(day == 30 && month == 4, 6, 9, 11) ||
|
55
|
+
(day > 28 && month == 2) ||
|
56
|
+
(day > 29 && month == 2 && year % 4 == 0)
|
57
|
+
) {
|
58
|
+
day -= 12;
|
59
|
+
month += 1;
|
60
|
+
console.log(
|
61
|
+
String(year) +
|
62
|
+
"年" +
|
63
|
+
String(month) +
|
64
|
+
"月" +
|
65
|
+
String(day) +
|
66
|
+
"日" +
|
67
|
+
String(hour) +
|
68
|
+
"時"
|
69
|
+
);
|
70
|
+
if (month > 12) {
|
71
|
+
year += 1;
|
72
|
+
}
|
73
|
+
}
|
74
|
+
}
|
75
|
+
|
76
|
+
date =
|
77
|
+
String(year) +
|
78
|
+
"年" +
|
79
|
+
String(month) +
|
80
|
+
"月" +
|
81
|
+
String(day) +
|
82
|
+
"日" +
|
83
|
+
String(hour) +
|
84
|
+
"時";
|
85
|
+
|
86
|
+
if (json.list[i].weather[0].main == "Clear") {
|
87
|
+
tenki = "はれ";
|
88
|
+
} else if (json.list[i].weather[0].main == "Clouds") {
|
89
|
+
tenki = "くもり";
|
90
|
+
} else if (json.list[i].weather[0].main == "Rain") {
|
91
|
+
tenki = "あめ";
|
92
|
+
}
|
93
|
+
|
94
|
+
$(".container").append(
|
95
|
+
$(".table").append(
|
96
|
+
$(".tbody").append(
|
97
|
+
$('<tr id="data' + i + '"></tr>').append([
|
98
|
+
$("<td></td>").text(date),
|
99
|
+
$("<td></td>").html(
|
100
|
+
' <img src="' +
|
101
|
+
"http://openweathermap.org/img/w/" +
|
102
|
+
json.list[i].weather[0].icon +
|
103
|
+
'.png"> '
|
104
|
+
),
|
105
|
+
$("<td></td>").text(tenki)
|
106
|
+
])
|
107
|
+
)
|
108
|
+
)
|
109
|
+
);
|
110
|
+
}
|
111
|
+
});
|
112
|
+
});
|
113
|
+
</script>
|
114
|
+
</head>
|
115
|
+
|
116
|
+
<body>
|
117
|
+
<h1>天気予報</h1>
|
118
|
+
<div>
|
119
|
+
<p id="place"></p>
|
120
|
+
</div>
|
121
|
+
|
122
|
+
<div class="container">
|
123
|
+
<table class="table">
|
124
|
+
<thead>
|
125
|
+
<tr>
|
126
|
+
<th>date</th>
|
127
|
+
<th>icon</th>
|
128
|
+
<th>weather</th>
|
129
|
+
</tr>
|
130
|
+
</thead>
|
131
|
+
<tbody class="tbody">
|
132
|
+
<div class="data"></div>
|
133
|
+
</tbody>
|
134
|
+
</table>
|
135
|
+
</div>
|
136
|
+
</body>
|
137
|
+
</html>
|
138
|
+
|
36
139
|
```
|