用javascript写了一个倒计时器,不知为什么时间一到60秒就老是出错,停在那里了。求教了!<script language="javascript" type="text/javascript">
function Format(data){
return (data>9?data:"0"+data);
}
function Show()
{
totaltime --;
if(totaltime>60)
{
second = totaltime%60;
minute = (totaltime-second)/60;
time = "剩余时间:" + Format(minute) + "分" + Format(second) + "秒"
}
else
{
time = "剩余时间:" + "00" + "分" + Format(s) + "秒"
}
divclock.innerText = time;
}
var totaltime = 67;
window.setInterval("Show();",1000);
</script>顺便问一下 javascript里面的除号(/) 除出来的是小数还是取整的啊?我想要取得商的整数部分,好像直接用除号或者floor()函数都不行啊!
function Format(data){
return (data>9?data:"0"+data);
}
function Show()
{
totaltime --;
if(totaltime>60)
{
second = totaltime%60;
minute = (totaltime-second)/60;
time = "剩余时间:" + Format(minute) + "分" + Format(second) + "秒"
}
else
{
time = "剩余时间:" + "00" + "分" + Format(s) + "秒"
}
divclock.innerText = time;
}
var totaltime = 67;
window.setInterval("Show();",1000);
</script>顺便问一下 javascript里面的除号(/) 除出来的是小数还是取整的啊?我想要取得商的整数部分,好像直接用除号或者floor()函数都不行啊!
<script language="javascript" type="text/javascript">
var divclock = document.getElementById("divclock");
function Format(data){
return (data>9?data:"0"+data);
}
function Show()
{
totaltime --;
second = totaltime%60; if(totaltime > 59)
{
minute = (totaltime-second)/60;
time = "剩余时间:" + Format(minute) + "分" + Format(second) + "秒"
}
else
{
time = "剩余时间:" + "00" + "分" + Format(second) + "秒"
}
divclock.innerText = time;
}
var totaltime = 67;
window.setInterval("Show();",1000);
</script>
1. 把second的赋值放到外面,
2. 把60改成59
if(totaltime == 60) alert("还有一分钟");不过这样会阻塞线程, 计时会停下来, 想要计时继续, 可以用div模拟alert对话框, 搜索下这个 ymprompt
<!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>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<script type="text/javascript" src="http://www.ajaxbbs.net/test/ymPrompt4.0/ymPrompt.js"></script>
<link rel="stylesheet" id='skin' type="text/css" href="http://www.ajaxbbs.net/test/ymPrompt4.0/skin/qq/ymPrompt.css" />
</head>
<body>
<div id="divclock"></div>
<script language="javascript" type="text/javascript">
function Format(data){
return (data>9?data:"0"+data);
}
function Show()
{
totaltime --;
if(totaltime>60)
{
second = totaltime%60;
minute = (totaltime-second)/60;
time = "剩余时间:" + Format(minute) + "分" + Format(second) + "秒"
}
else
{
time = "剩余时间:" + "00" + "分" + Format(totaltime) + "秒"
}
divclock.innerText = time;
if(totaltime == 60) ymPrompt.alert("还有一分钟");
}
var totaltime = 62;
window.setInterval("Show();",1000);
</script>
</body>
</html>