javascript 寫的一個簡單的timer

來源:互聯網
上載者:User

先看看效果吧。

代碼很簡單,只是使用了javascript的setTimeout()函數。
用到的html"

複製代碼 代碼如下:<table>
<td bgcolor="EE8F8F" height="45">
<img src="dg8.gif" src="dg8.gif" name="hr1"><img
src="dg8.gif" name="hr2"><img
src="dgc.gif" name="c"><img
src="dg8.gif" name="mn1"><img
src="dg8.gif" name="mn2"><img
src="dgc.gif" name="c"><img
src="dg8.gif" name="se1"><img
src="dg8.gif" name="se2">
</td></table>

然後是實現了不停的計時的javascript:複製代碼 代碼如下:<script language="javascript"><!--
dg0 = new Image();dg0.src = "dg0.gif";
dg1 = new Image();dg1.src = "dg1.gif";
dg2 = new Image();dg2.src = "dg2.gif";
dg3 = new Image();dg3.src = "dg3.gif";
dg4 = new Image();dg4.src = "dg4.gif";
dg5 = new Image();dg5.src = "dg5.gif";
dg6 = new Image();dg6.src = "dg6.gif";
dg7 = new Image();dg7.src = "dg7.gif";
dg8 = new Image();dg8.src = "dg8.gif";
dg9 = new Image();dg9.src = "dg9.gif";

dgc = new Image();dgc.src = "dgc.gif";
se_d=0;
se_g=0;
mn_g=0;
mn_d=0;
hr_g=0;
hr_d=0;
function dotimer(){
theTime=setTimeout('dotimer()',1000);

//���ﲻ��ʹ��60����4����hr,mn��se
//������ʹ�øߣ���λ4��ʾ

document.hr1.src = 'dg'+hr_g+'.gif';
document.hr2.src = 'dg'+hr_d+'.gif';
document.mn1.src = 'dg'+mn_g+'.gif';
document.mn2.src = 'dg'+mn_d+'.gif';
document.se1.src = 'dg'+se_g+'.gif';
document.se2.src = 'dg'+se_d+'.gif';
if(se_d < 9)
{
se_d=se_d +1;}
else
{
se_d=0;
se_g=se_g+1;
}
if(se_g > 5)
{se_g = 0;
mn_d=mn_d +1 ;
if(mn_d > 9)
{mn_d =0;
mn_g = mn_g+1;}
if(mn_g >5)
{
mn_g=0;
hr_d=hr_d+1;
}
if(hr_d >9)
{
hr_d=0;
hr_g=hr_g+1;
}
}
}

dotimer();
//end
// --></script>

最後附上我用到的幾個圖片:

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.