setTimeout()执行时序

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>SETTIMEOUT</title>
<script type="text/javascript">
var len=4;
var t = null;
while(len--){
t = setTimeout("showinfo(len,t)",2000);
document.write(len+"  ");
}
document.write("<br/>");
document.write("    abc"+len);

function showinfo(num1,num2)
{
document.write("len:"+num1+"  t:"+num2);
}
</script>
</head>

<body>
<div></div>
</body>

</html>

网页显示:

首先输出:

3  2  1  0  
    abc-1

2s后输出:

len:-1  t:10

setTimeout()启动后,与其他字段同时执行。

posted on 2015-10-22 15:49  菜鸟Z  阅读(149)  评论(0编辑  收藏  举报

导航