Prevent JavaScript function from running twice (setTimeout)
问题 I have this function that runs for several seconds with the use of setTimeout . This function is ran when a button is clicked. function complete() { var div = document.getElementById('log'); setTimeout(function(){ div.innerHTML = div.innerHTML + intro[Math.floor(Math.random() * intro.length)] + "<br>"; }, 500); setTimeout(function(){ div.innerHTML = div.innerHTML + second[Math.floor(Math.random() * second.length)] + "<br>"; }, 2560); setTimeout(function(){ div.innerHTML = div.innerHTML +