<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> <title></title> </head> <body> <span id="timeout">0</span>秒后返回首页 <script type="text/javascript"> var timestart = 30; var timestep = -1; var timeID; function timecount() { document.getElementById("timeout").innerHTML = timestart; timestart += timestep; if(timestart < 0){ alert(12) timestart = 30; //倒计时为0时执行xxxx方法 } timeID=setTimeout("timecount()",1000); } timecount() </script> </body> </html>
标签:timestart,timestep,js,倒计时,timeID,简单,var,timecount From: https://www.cnblogs.com/hualingyun/p/17102848.html