Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!DOCTYPE html>
- <html lang="hu">
- <head>
- <meta charset="UTF-8">
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
- <title>Timer</title>
- </head>
- <body>
- <div id="timer">00 : 00 : 00,0</div>
- <button type="button" onclick="change() == 'Start' ? clearInterval(myTimer) : myTimer = setInterval(timer,100);"
- name="timerid" id="timerid">Start</button>
- <script type="text/javascript">
- var myTimer = 0;
- num = 0;
- function timer() {
- num++;
- b = Math.floor(num / 60 / 60 / 10);
- num0 = num - b * 60 * 60 * 10
- c = Math.floor(num0 / 60 / 10);
- num0 = num0 - c * 60 * 10
- d = Math.floor(num0 / 10);
- e = num0 - d * 10
- if (b < 10) {
- b = "0" + b;
- }
- if (c < 10) {
- c = "0" + c;
- }
- if (d < 10) {
- d = "0" + d;
- }
- document.getElementById("timer").innerHTML = b + " : " + c + " : " + d + "," + e;
- }
- function change() {
- let item = document.getElementById("timerid");
- if (item.innerHTML == "Start") {
- item.innerHTML = "Stop";
- }
- else {
- item.innerHTML = "Start";
- }
- return item.innerHTML;
- }
- </script>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement