Auto-update by id in Javascript?


Warning: count(): Parameter must be an array or an object that implements Countable in /home/styllloz/public_html/qa-theme/donut-theme/qa-donut-layer.php on line 274
0 like 0 dislike
6 views
Good day!
There is a simple code with two functions.
The first function looks up the current time and assigns values to variables.
The second function needs to perform the first function, and display the result in the browser, namely, to change the data in the id.
Everything works when you manually refresh the page, and automatically when you use setInterval not. Why?
Code:
<!DOCTYPE html>TestNo. 1: No. 2: No. 3: var D = new Date(); // Получение текущего времениvar D_M = D.getMinutes(); // Минутыvar a = 1;var b = 2;var c = 3;var d = 4;var e = 5;var f = 6;function Test(){switch (D_M){case 01:a = b;c = d;e = f;break;case 02:a = f;c = b;e = d;break;case 03:a = d;c = f;e = b;break;};}function Test1(){Test();document.getElementById('test_1').innerHTML = a;document.getElementById('test_2').innerHTML = b;document.getElementById('test_3').innerHTML = c;}setInterval(Test1, 1000);
by | 6 views

1 Answer

0 like 0 dislike
You get once during initialization, and the values never change. Transfer the time into the function Test:
function Test(){ var D = new Date(); // Get current time var D_M = D. getMinutes(); // Minutes /* rest of function code */ }
by

Related questions

110,608 questions
257,186 answers
0 comments
35,573 users