Answer the question
In order to leave comments, you need to log in
Is executing a stored procedure in MySQL one transaction?
Is executing a stored procedure in MySQL one transaction? In other words, can someone change the data in the tables it works with while the procedure is running? Whether it is necessary to do LOCK TABLE in procedure?
Answer the question
In order to leave comments, you need to log in
If you need to perform some action every second, then it is more correct to use setInterval :
function startTimer(secs) {
var i = 0;
var timer = document.getElementById('timer');
var interval = setInterval(function() {
if (++i >= secs) {
clearInterval(interval);
timer.innerHTML = 'Done!';
} else {
++timer.innerHTML;
}
}, 1000);
}
startTimer(10);
Demo. function startTimer(secs) {
var timer = document.getElementById('timer');
setTimeout(function() {
timer.innerHTML = 'Done!';
}, secs * 1000);
}
startTimer(10);
Demo.
You are not using setTimeout
correctly
Look at what should be passed in the parameters, and what you have.
First, you are trying to call a function within itself. Secondly, the syntax of the if condition is incorrect.
If I understood the task correctly, then it should look like this:
function timer() { //Объявили функцию
var s = Number(document.getElementById("timer").innerHTML); //Получили число из дива
s++; //Увеличили на единичку
if (s < 10) { //Если число меньше десяти
document.getElementById("timer").innerHTML = s; //В див выведем новое значение s
} else { //Если нет, т.е. если число меньше 10, то напишем 12
document.write("12");
}
}
//Подождем 1000 мс после загрузки страницы и вызовем функцию
setTimeout(timer, 1000);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question