我编写了这段代码来计算秒数(用 decisec 和 centisec)。
You've wasted time <span id="alltime">0.00</span> seconds.
<script type="text/javascript">
function zeroPad(num,count)
{
var numZeropad = num + '';
while(numZeropad.length < count) { numZeropad = "0" + numZeropad; }
return numZeropad; }
function counttwo() {
tall = document.getElementById('alltime').innerHTML;
if(parseFloat(tall) < 1.00) { tnew2 = tall.replace('0.0','').replace('0.',''); }
else { tnew2 = tall.replace('.',''); }
tnum = parseInt(tnew2) + 1;
//check if have to add zero
if(tnum >= 100) { tstr1 = tnum + ''; }
else { tstr1 = zeroPad(tnum,3); }
tlast = tstr1.substr(0,tstr1.length - 2) + '.' + tstr1.substr(tstr1.length - 2);
document.getElementById("alltime").innerHTML = tlast;
}
var inttwo=setInterval("counttwo()",10);
</script>
在 HTML 文件中运行。
它运行良好,但是当我使用 Firefox 4 并运行代码时。当它在某些数字上(随机像 12.20、4.43)时,它似乎有点滞后(在计数之前停下来)。我尝试将“counttwo()”更改为 counttwo,但这无济于事。
我已经告诉我的一些朋友也可以在 Firefox 4 上运行。他们说它根本不落后。这个原因是因为我的电脑吗?还是我的火狐?或者是其他东西 ?
提前致谢!
PS。在这里小提琴:http: //jsfiddle.net/XvkGy/5/镜像:http ://bit.ly/hjVtXS