计时器setTimeout()
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>定时器</title> <script type = "text/Javascript"> //开始计时的函数 function clock(){ var time = new Date(); var attime=time.getHours()+":"+time.getMinutes()+":"+time.getSeconds(); document.getElementById("clock").value = attime; } //定义函数clock2(),实现点击Start按钮后延迟5秒打开百度在首页 function clock2(){ setTimeout(window.open("http://www.baidu.com","_blank","width=600px,height=400px"),5000); } //每隔100毫秒调用函数clock(),并将返回值赋给变量i var i = setInterval("clock()",1000); </script> </head> <body> <form> <input type="text" id="clock" size="4" /> <input type="button" value="Stop" onclick="clearInterval(i)"/><br> <input type = "button" value = "Start" onclick = "clock2()"/> </form> </body> </html>
函数clock2()要实现的功能是点击Start按钮后延迟5秒打开百度。执行完之后怎么不延迟直接打开了呢?