易截截图软件、单文件、免安装、纯绿色、仅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动态添加DOM元素总结

这两天开始写古代地图的GIS网站,说白了就是用古代地图的内容效仿山寨一下谷歌地图。
JS这东西很久没写了,有些概念也很模糊,导致完成分块拖动加载的功能就花了好多时间。
主要问题是出在拖动时对元素内容的动态修改上,总结下。
通过JS脚本动态修改DOM元素内容通常有两种方法:
1. 通过DOM标准接口创建元素
var new ......

javascript技术技巧大全

//各种尺寸
s  +=  "\r\n网页可见区域宽:"+  document.body.clientWidth;  
s  +=  "\r\n网页可见区域高:"+  document.body.clientHeight;  
s  +=  "\r\n网页可见区域高:"+  document.body.offs ......

JavaScript 笔记 myhere

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

javascript , ajax

问:
Hi,
I have this C#/ASP.NET/.aspx page with a string variable named myString with the value "Mario Gamito".
How can I access "Mario Gamito" from within a JavaScript function, i. e., the variable's value ?
Already tried '" + mystring + "' but it doesn't works.
Any help would be appreciated.
......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号