-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAufgabe 5.2.html
102 lines (83 loc) · 3.39 KB
/
Aufgabe 5.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
<html>
<head></head>
<body>
<h1>Rednerliste</h1>
<label>Neuer Redner:</label>
<input type="text">
<button>Hinzufügen</button>
<ul></ul>
</body>
<script>
const input = document.querySelector('input');
const button = document.querySelector('button');
const list = document.querySelector('ul');
button.onclick = function(){
const value = input.value
const listItem = document.createElement('li');
list.appendChild(listItem);
listItem.innerHTML = `${value} <span>time</span> <button>Start</button>`;
input.value = "";
input.focus();
const startStopBtn = listItem.querySelector('button');
//----Folgenden code habe ich aus dem Internet kopiert:--------
//timer
const timer = listItem.querySelector('span');
var h=0;
var m=0;
var s=0;
//var time = "";
//debugger;
function startOrStopTimer(){
switch(startStopBtn.textContent){
case 'Stop':
window.clearInterval(timer.value); // stop the timer
startStopBtn.textContent = 'Start';
break;
case 'Start':
timer.value = window.setInterval(disp,1000); //set the interval Id into timer.value...use later on (above) to clear this interval!
startStopBtn.textContent = 'Stop';
var allRedner = list.getElementsByTagName('li')
for(var i = 0, max = allRedner.length; i < max; i++) {
if(allRedner[i] != listItem){ //aktueller Redner
allRedner[i].querySelector('button').textContent = 'Start' //Timer Button auf "Start" setzen
window.clearInterval(allRedner[i].querySelector('span').value);
}
}
break;
}
}
startOrStopTimer();
startStopBtn.onclick = startOrStopTimer;
function disp(){
// Format the output by adding 0 if it is single digit //
if(s<10){var s1='0' + s;}
else{var s1=s;}
if(m<10){var m1='0' + m;}
else{var m1=m;}
if(h<10){var h1='0' + h;}
else{var h1=h;}
// Display the output //
var str= h1 + ':' + m1 +':' + s1 ;
timer.innerHTML = str;
// Calculate the stop watch //
if(s<59){
s=s+1;
}else{
s=0;
m=m+1;
if(m==60){
m=0;
h=h+1;
} // end if m ==60
}// end if else s < 59
// end of calculation for next display
}
}
//---------------------Ende Kopie aus internet------------------
input.onkeydown = function(event){
if(event.key === 'Enter'){
button.click();
}
}
</script>
</html>