欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

javascript中interval與setTimeOut的區(qū)別示例介紹

 更新時(shí)間:2014年03月14日 17:09:36   作者:  
這篇文章主要介紹了javascript中interval與setTimeOut的區(qū)別,需要的朋友可以參考下
setTimeout(code,millisec) //- 在指定時(shí)間后執(zhí)行代碼

code必須;

millisec必須;

clearTimeout(setTimeoutId) //- 取消 setTimeout()

setInterval(code,millisec);//指定間隔毫秒內(nèi)循環(huán)執(zhí)行代碼

code必須;

millisec必須;

clearInterval(intervalId);

用setTimeout(code,millisec)可以實(shí)現(xiàn)setInterval效果,只需要嵌套調(diào)用方法即可;

下面是一個(gè)倒計(jì)時(shí)頁面
復(fù)制代碼 代碼如下:

<!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">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>無標(biāo)題文檔</title>
<script type="text/javascript">
var c=6;
var t;
function timedCount()
{
var time = document.getElementById('txt').value;
if( time>0){
document.getElementById('txt').value=c;
c=c-1;
t=setTimeout("timedCount()",1000);
}
else{
clearTimeout(t);
}

}
</script>
</head>
<body>
<form>
<input type="button" value="開始計(jì)時(shí)!" onClick="timedCount()">
<input type="text" id="txt" value="6">
</form>
</body>
</html>

相關(guān)文章

最新評(píng)論