Start/stop setTimeout with a button & prevent counting faster with more clicks
问题 I am working with JavaScript and I use a setTimeout function in order to count up. Here is my code... <button id="star">Start</button> <p id="time">0</p> var timeEl = 0; function start() { time(); } function time() { setTimeout(function() { timeEl = timeEl + .1; timeEnd = timeEl.toFixed(1); document.getElementById("time").innerHTML = timeEnd; time(); }, 100); } var el = document.getElementById("star"); el.addEventListener("click", star, false); How do I get my setTimeout function to start on