質問編集履歴
3
文法修正
test
CHANGED
File without changes
|
test
CHANGED
@@ -4,7 +4,7 @@
|
|
4
4
|
|
5
5
|
HTMLのナンバーインプットで計りたい時間を入力してスタートボタンを押すとその時間でカウントダウンが開始するようにしたいです。
|
6
6
|
|
7
|
-
どのように書き直せば入力した値を取得できるか
|
7
|
+
どのように書き直せば入力した値を取得できるでしょうか。
|
8
8
|
|
9
9
|
|
10
10
|
|
@@ -104,6 +104,8 @@
|
|
104
104
|
|
105
105
|
|
106
106
|
|
107
|
+
|
108
|
+
|
107
109
|
start.onclick = function(){
|
108
110
|
|
109
111
|
time = document.getElementById("time");
|
2
ソースコード記入
test
CHANGED
File without changes
|
test
CHANGED
@@ -20,8 +20,42 @@
|
|
20
20
|
|
21
21
|
```html
|
22
22
|
|
23
|
+
<!DOCTYPE html>
|
24
|
+
|
25
|
+
<html lang="ja">
|
26
|
+
|
27
|
+
<head>
|
28
|
+
|
29
|
+
<meta charset="utf-8">
|
30
|
+
|
31
|
+
<title></title>
|
32
|
+
|
33
|
+
<link rel="stylesheet" href="css/style.css">
|
34
|
+
|
35
|
+
<script src="js/main.js"></script>
|
36
|
+
|
37
|
+
|
38
|
+
|
39
|
+
</head>
|
40
|
+
|
41
|
+
|
42
|
+
|
43
|
+
<body>
|
44
|
+
|
45
|
+
<div id="timer">
|
46
|
+
|
47
|
+
<h1>Timer</h1>
|
48
|
+
|
23
49
|
<p>
|
24
50
|
|
51
|
+
<span id="min">0</span> 分
|
52
|
+
|
53
|
+
<span id="sec">0</span> 秒
|
54
|
+
|
55
|
+
</p>
|
56
|
+
|
57
|
+
<p>
|
58
|
+
|
25
59
|
<input type="button" id="start" value="START">
|
26
60
|
|
27
61
|
<input type="button" id="stop" value="STOP" disabled>
|
@@ -32,14 +66,44 @@
|
|
32
66
|
|
33
67
|
</p>
|
34
68
|
|
69
|
+
</div>
|
70
|
+
|
71
|
+
|
72
|
+
|
73
|
+
</body>
|
74
|
+
|
75
|
+
</html>
|
76
|
+
|
77
|
+
|
78
|
+
|
35
79
|
```
|
36
80
|
|
37
81
|
```javaScript
|
38
82
|
|
83
|
+
|
84
|
+
|
85
|
+
window.onload = function(){
|
86
|
+
|
87
|
+
var counter;
|
88
|
+
|
89
|
+
|
90
|
+
|
91
|
+
var start = document.getElementById("start");
|
92
|
+
|
93
|
+
var stop = document.getElementById("stop");
|
94
|
+
|
95
|
+
var reset = document.getElementById("reset");
|
96
|
+
|
97
|
+
var min = document.getElementById("min");
|
98
|
+
|
99
|
+
var sec = document.getElementById("sec");
|
100
|
+
|
39
101
|
var time = document.getElementById("time");
|
40
102
|
|
41
103
|
|
42
104
|
|
105
|
+
|
106
|
+
|
43
107
|
start.onclick = function(){
|
44
108
|
|
45
109
|
time = document.getElementById("time");
|
@@ -50,6 +114,84 @@
|
|
50
114
|
|
51
115
|
|
52
116
|
|
117
|
+
|
118
|
+
|
119
|
+
}
|
120
|
+
|
121
|
+
stop.onclick = function(){
|
122
|
+
|
123
|
+
clearInterval(counter);
|
124
|
+
|
125
|
+
toggle();
|
126
|
+
|
127
|
+
}
|
128
|
+
|
129
|
+
reset.onclick = function(){
|
130
|
+
|
131
|
+
time = 0;
|
132
|
+
|
133
|
+
sec.innerHTML = time % 60;
|
134
|
+
|
135
|
+
min.innerHTML = Math.floor(time / 60);
|
136
|
+
|
137
|
+
}
|
138
|
+
|
139
|
+
|
140
|
+
|
141
|
+
|
142
|
+
|
143
|
+
function toggle(){
|
144
|
+
|
145
|
+
if( start.disabled){
|
146
|
+
|
147
|
+
start.disabled = false;
|
148
|
+
|
149
|
+
stop.disabled = true;
|
150
|
+
|
151
|
+
} else {
|
152
|
+
|
153
|
+
start.disabled = true;
|
154
|
+
|
155
|
+
stop.disabled = false;
|
156
|
+
|
157
|
+
}
|
158
|
+
|
159
|
+
}
|
160
|
+
|
161
|
+
|
162
|
+
|
163
|
+
function count() {
|
164
|
+
|
165
|
+
|
166
|
+
|
167
|
+
if( time === 0) {
|
168
|
+
|
169
|
+
sec.innerHTML = 0;
|
170
|
+
|
171
|
+
min.innerHTML = 0;
|
172
|
+
|
173
|
+
toggle();
|
174
|
+
|
175
|
+
alert("3分経過しました。");
|
176
|
+
|
177
|
+
clearInterval(counter);
|
178
|
+
|
179
|
+
} else {
|
180
|
+
|
181
|
+
time -= 1;
|
182
|
+
|
183
|
+
sec.innerHTML = time % 60;
|
184
|
+
|
185
|
+
min.innerHTML = Math.floor(time / 60);
|
186
|
+
|
187
|
+
}
|
188
|
+
|
189
|
+
}
|
190
|
+
|
191
|
+
}
|
192
|
+
|
193
|
+
|
194
|
+
|
53
195
|
```
|
54
196
|
|
55
197
|
|
1
マークダウン記法使用に変更。
test
CHANGED
File without changes
|
test
CHANGED
@@ -18,7 +18,7 @@
|
|
18
18
|
|
19
19
|
|
20
20
|
|
21
|
-
|
21
|
+
```html
|
22
22
|
|
23
23
|
<p>
|
24
24
|
|
@@ -32,9 +32,9 @@
|
|
32
32
|
|
33
33
|
</p>
|
34
34
|
|
35
|
+
```
|
35
36
|
|
36
|
-
|
37
|
-
j
|
37
|
+
```javaScript
|
38
38
|
|
39
39
|
var time = document.getElementById("time");
|
40
40
|
|
@@ -48,7 +48,9 @@
|
|
48
48
|
|
49
49
|
toggle();
|
50
50
|
|
51
|
+
|
52
|
+
|
51
|
-
|
53
|
+
```
|
52
54
|
|
53
55
|
|
54
56
|
|