<body> <spanid="clock"style="font-size: 3em">00:30:00:00</span> <scripttype="text/javascript"> var oclock=document.getElementById("clock"); var start1 = oclock.innerHTML; var finish = "00:00:00:00"; var timer = null;
var hms = newString(start1).split(":");//以:作为分隔符号取字符串内的数据 var ms = newNumber(hms[3]);//给每个数据定义对象 var s = newNumber(hms[2]); var m = newNumber(hms[1]); var h = newNumber(hms[0]);
ms -= 10;//每次执行ms减10
if (ms < 0)//判断时间并进行变化 { ms = 90; s -= 1; if (s < 0) { s = 59; m -= 1; } if (m < 0) { m = 59; h -= 1; } } var ms = ms < 10 ? ("0" + ms) : ms;//如果出现个位数给个位数前面添加0 var ss = s < 10 ? ("0" + s) : s; var sm = m < 10 ? ("0" + m) : m; var sh = h < 10 ? ("0" + h) : h; start1 = sh + ":" + sm + ":" + ss + ":" + ms; oclock.innerHTML = start1;//重新给oclock赋值 } </script> </body> </heml>