Using setTimeout and setInterval

十二月 4, 2008 作者:  

In JavaScript ,setTimeout and setInterval can perform codes after some time you gived. Their syntax are same. Their have two parameters. One is codes that will be performed, the other is time that the unit is milliseconds. In fact, the two function are different.  Finished first performing the codes, after the fixed time interval, setInterval will automatically repeat perfoming the codes. setTimeout only performs the codes once.The work mode of  setTimeout  is like on-off. For example,

setTimeout(“showTime()”, 5000);
function showTime()
{
var today = new Date();
window.alert(“The time is: ” + today.toString());
}

After running the codes, we will see “The time is: Thu Dec 4 10:51:47 UTC+0800 2008” on the screen.

setInterval(“showTime()”, 5000);
function showTime()
{
var today = new Date();
window.alert(“The time is: ” + today.toString());
}

After running the codes,we will have to click the confirm button every 5 seconds. (It’s a problem. you must shutdown the browers within 4 second. Good luck~~)

If you write your codes like this, setTimeout will not be on-off. It’s circulation,becomes setInterval.

setTimeout(“showTime()”, 5000);
function showTime()
{
var today = new Date();
window.alert(“The time is: ” + today.toString());
setTimeout(“showTime()”,5000);
}

If you observe the codes and result carefully,you’ll find that the second and the third codes are different. setInterval can automatically perform the codes every time interval you set. The time interval is very exact. If your codes performed by setInterval are prolix and complex. The runtime may be longer than the time interval, But setInterval  still performs the codes when the time is out. In the third codes ,setTimeout can perform the codes every 5 second, the difference is that  completed  the implementation of the code ,setTimeout will run again after 5 seconds. If the time of performing the code is 2 seconds, setTimeout will be perfomed after 7 seconds. Between the two implementations, time interval is 7 seconds. The two implementations are not disturb each other.

when setTimeout and setInterval are performed ,they return “Time ID”.  Using the “Time ID”, we can stop them. With it, we will not need to close your browser directly. “clearInterval(TimeID)” is used to stop setInterval. “clearTimeout(TimeID)” is used to stop other. For example,

<script type=text/javascript>
var intervalProcess = setInterval(“alert(‘setInterval is running’)”, 5000);

function stopsetInterval()
{
clearInterval(intervalProcess);
}
</script>
<button onclick=”stopsetInterval()” > Stop setInterval </button>

when you click the button,the setInterval is stop. Using clearTimeout ,you can stop setTimeout when the time is not out.

<script type=text/javascript>
var timeoutProcess = setTimeout(“alert(‘setInterval is running’)”, 5000);

function stopsetTimeout()
{
clearTimeout(timeoutProcess);
}
</script>
<button onclick=”stopsetTimeout()” > Stop setTimeout </button>

In 5 seconds , you can click the button to stop the setTimeout.

别了,51

十二月 11, 2007 作者:  

51.net 的空间用6年了吧,自已都有点记不清楚了,终于在今年,不能在忍受低PHP版本、低MySQL版本,价格又贵,决定更换主机。找同学联系了一下,搞来了一个空间,准备把校友录放到他那里去,虽然校友录几乎没有人访问,但是仍然不想就这么关闭他。主要是自己也没有及时的升级更新校友录的程序,导致功能严重落后,当时也没有能很好的宣传。这个空间决定只放自己的Blog算了,随便的写写画画。

现在把SRM系统投入使用,开发时的懒散,上线前的随闷,都给现在带来了不少的麻烦。可是似乎每天又没有什么时间来搞他,总是被很多的事情纠缠着。但是仔细想想,时间还是应该有的,但是都被自己给浪费了。同样的,51的6年自己浪费了,几乎有三年的时间也被浪费了。浪费掉了不仅仅是自己的时间、金钱。更重要的是浪费了自己,使技术水平没有再提高。虽然当年已经是达到了586的水平,但是到现在也仅仅是个PIII了,别说什么讯驰,双核,四核了。还是那句老话,I’m 286。

同样的,51的空间感觉也有这种效果,当年的也还算得上一个不错的地方,可是经过这几年他依然没有什么变化还是老样子,空间大小,软件,价格都是雷打不动。“没有进步,就是退步”,他和我都是这样的一个例子,我们同样在原地踏步,我的结果是技术水平落后,依然是个民兵(这里没有其它的意思)永远都比不了正规军。他的结果呢,失去了客户,只少我就是。当数据全部拖回本地后就要正式的同他说拜拜了,也许他也有一点点的留恋,还是故意跟我找麻烦。向回拖数据的过程很是不顺利,不过如何,我已狠下杀手,决定将你抛弃。认命吧,我的51,跟我共同生活了6年的51。

别了,6年的朝夕相处。别了,超低的软件版本,别了,高昂的价格。别了,51.net。

茫然

七月 22, 2007 作者:  

???????????, discount ???????????????,??????????????????????????????????????????????????????????

???????????????????1900????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????makeit.cn?????????????????????????????????????????????????????????????????????????????????????

????????????????????????VC??java,?pyhton???????make??????????????????????????????????????????????????????????????????????????????

What am I going to do?

第二次

七月 21, 2007 作者:  

??????????????????????
???????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????CS?????????????????????????????????????????????????????????????????????????????????????

???????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????VOD??????????????????????????????????????????????????????????????????????“?????????????????????????????????????”???????????????????????????????????????????????????????????????????????????????“Loading”???????????????????????????????????????????????????????????????????pro?sword???????????????????????????????????????????????????????????????????sword, shop pro??????????????????“???”????????????????????????????????????????

?????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????

?????????????????????

烦乱

四月 4, 2007 作者:  

       ????Think???????????????????????????????????????????JavaScript, recipe Ajax, no rx Prototype, capsule JSON,IE,FireFox……????????????????????????????????

      ??????????????????????????????????????????????“?????????????”???????????????????????????????????????????????????????

        ?????????????????????????????????????????????????????????

        ??5???Restart ???

忙碌的日子又快要到了

二月 6, 2007 作者:  

      ??????????????????????????????????????????????????????

      ????VM???????????????Fedora 6?????Redhat Enterprise Advanced Server 4 ???????????????????????Fedora 6???

      ?????????????????N????????????????Security Linux??????????????linux?????????B1???????????????????????????????????????????????????????????????????apache, discount php,mysql,python?

      ?????????????????????????????????????