javascript - Stop timeout within a function from another function -
function one(){ settimeout(function(){ two(); },3000); } function two(){ settimeout(function(){ one(); },3000); } function stop(){ alert('this should run,and functions above should stop'); }
i want stop autorun of first 2 functions,when click on third. now,if click on third,the alert shows up,but loop continue.any way of doing this?
var onetimeout, twotimeout; function one(){ onetimeout = settimeout(function(){ two(); },3000); } function two(){ twotimeout = settimeout(function(){ one(); },3000); } function stop(){ cleartimeout(onetimeout); cleartimeout(twotimeout); alert('this should run,and functions above should stop'); }
Comments
Post a Comment