function waitExe(param){
if(time < 20){
time ++;
$("#content").html(time);
var self=this;
timeout = window.setTimeout(function(){
self.waitExe(param)
}, 2000)
}else{
alert(param);
clearTimeout(timeout);
}
}
function f_testSetTimeOut(){
time = 0;
waitExe('gg');
$("#content").html('---------');
}
<input type="button" value="setTimeOut测试" onclick="f_testSetTimeOut();"/>
<div id="content">--</div>