+ 1
Need some help with this code
I want to make a progress bar which only clickable once and stops when the other button is pressed but I am having problem in the clicking only once part as u can see in the below code when u press the button more than once u can speed up the progress bar but I don't want it to happen. so any help will be appreciated! https://code.sololearn.com/WHT822ao9n7m/?ref=app
3 Réponses
+ 4
// Quite different solution:
var btm;
var ti = null; // for later easiest handling
var v = 0;
function c() {
// dont use 'var' keyword else you create a local variable rather than use the global var ^^
// and test the value of ti: if null you start the serInterval, else you cancel the setInterval and reset ti:
if (ti===null)
ti = setInterval(m,100);
else {
clearInterval(ti);
ti = null;
}
}
function m() {
var btm = document.getElementById("p").value = v++;
}
+ 15
var btm;
var ti;
var v = 0;
function c() {
var ti = setInterval(m,100);
c = function() {};
}
function m() {
var btm = document.getElementById("p").value = v++;
}
//Disable function after click
+ 2
thanks a lot