1、指定时间后执行一个动作,如3s后弹出一个对话框:
settimeout('alert("3s")',5000);
并且,该函数可以叠加起来是用,如:
function delay_times(){
settimeout('document.getelementbyid("time_text").innerhtml = "2s"',2000);
settimeout('document.getelementbyid("time_text").innerhtml = "4s"',4000);
settimeout('document.getelementbyid("time_text").innerhtml = "6s"',6000);
}
2、开始计数与停止计数
var count = 0;
var mytimer;
//开始计数
function start_counter(){
document.getelementbyid("time_count").innerhtml = count;
count++;
mytimer = settimeout("start_counter()",1000);
}
//停止计数
function stop_counter(){
cleartimeout(mytimer);
}