Prevent JavaScript function from running twice (setTimeout)

后端 未结 4 973
一整个雨季
一整个雨季 2021-01-12 13:10

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(         


        
4条回答
  •  轻奢々
    轻奢々 (楼主)
    2021-01-12 14:04

    for stop running timer you have to clear him

            var stopTimer;
    
            function someFunction() {
                stopTimer= setTimeout(function(){
                    console.log("something done");
                }, 3000);
            }
    
            function stopFunction() {
                clearTimeout(stopTimer);
            }
    

提交回复
热议问题