易截截图软件、单文件、免安装、纯绿色、仅160KB

javascript中setTimeout()函数

javascript中setTimeout()函数
大家都知道javascript中的setTimeput()函数的作用,一般会用他来处理一些连续的事情,们先看一个例子:
<head>
    <script>
        function init()
        {
            setTimeout("init2()",0);
            alert("1");
        }
        function init2()
        {
            alert("2");
        }
    </script>
</head>
<body onload="init()">
</body> 
也许很多人认为结果是:2 1, 而恰恰结果是:1  2 。这是为什么呢?明明延迟时间设置的是0,应该是立刻先执行init2()啊?我们可以这样认为,setTimeout()函数会自己重新申请一个堆栈空间,而不属于当前函数init()的堆栈空间,所以init()先入栈,alert("1")第2个入栈,当init()函数执行完后,setTimeout()才执行。
 
当然这里没有涉及到参数传递,再看这个例子:
<head>
<script>
  var rgbcolor=new Array(3);
  var whichtr=0;
  function changeColor(wh)
  {
  whichtr=wh;
  for(var i=0;i<3;i++)
  {rgbcolor[i]=Math.ceil(Math.random()*255);}
  trID[whichtr].style.backgroundColor="rgb("+rgbcolor[0]+","+rgbcolor[1]+","+rgbcolor[2]+")";
  setTimeout("changeColor("+whichtr+")",1000);
  }
  
</script>
</head> <body>
<table border="1" height="400" width="500" align="center" cellspacing="0">
  <tr onmousedown="changeColor(0)" id="trID"><td>0</td></tr


相关文档:

JavaScript 笔记 myhere

// 大学里最痛苦的事情莫过于做毕业设计,目前正处于这个时期。
// :( :(
//
// 首先记录下的是 Function 的一个问题
Function.prototype.method = function( name, func){
if( ! this.prototype[ name]){
this.prototype[ name ] = func;
}
} // 给 函数原型增加方法
//
// 给函数原型增加的方法在 St ......

JavaScript实现水平选项卡效果

 <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="WebApplication2._Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml ......

[读书笔记][JavaScript权威指南(第四版)][cookie]

//构造函数:用指定的名字和可选的性质为指定的文档创建一个cookie对象。
//参数:
// doucment:保存cookie的Document对象
// name: 指定cookie名的字符串
// hours: Number,指定从现在起到cookie过期的小时数
// path: String,指定cookie的路径性质
// domain: String, 指定cookie的域性质
// secure: Bo ......

[读书笔记][JavaScript权威指南(第四版)][DOM]

1.HTML文档树形表示
2.Node[] Node.childNodes 
//返回Node对象的所有字节点
3.Node.firstChild  /  lastChild  /nextSibling(下一个兄弟节点)  / previousSibling (上一个兄弟节点)  / parentNode
属性
4.Node.appendChild()  /  removeChild()  /  replaceChil ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号