javascript编写一个10秒倒计时,带小数点后两位显示,谢谢了~
4个回答
展开全部
<div id="seconds"></div>
<button id="startBtn">开始</button>
<script>
var maxTime=10,
startTime;
function timer(){
var passTime=(new Date().valueOf()-startTime)/1000;
if(passTime>=10){
passTime=10
document.getElementById("seconds").innerText="0.00"
}else{
setTimeout(timer,20);
document.getElementById("seconds").innerText=parseInt((maxTime-passTime)*100)/100
}
}
document.getElementById("startBtn").onclick=function(){
passTime=0;
startTime=new Date().valueOf();
timer()
}
</script>
展开全部
我帮你写写看看,写好了,你看看
<!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" xml:lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
<title>Document</title>
<script>
window.onload=function()
{
var timer=null;
var oTxt1=document.getElementById('txt1');
var n=10;
timer=setInterval(function(){
oTxt1.value="0."+toDuble(n);
n=n-1;
if(n<0)
{
clearInterval(timer);
}
},1000);
}
function toDuble(n)
{
if(n>=10)
{
return n+'';
}
else
{
return '0'+n;
}
}
</script>
</head>
<body>
<input type="text" name="" id="txt1" />
</body>
</html>
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
<div id="clock">10.00</div>
var $=function(x){
return document.getElementById(x);
};
var _t;
var clock=function(){
var t=$('clock').innerHTML;
if(t<=0){
clearTimeout(_t);
return;
}
t=parseFloat(t-0.01);
t=t.toFixed(2);
$('clock').innerHTML=t;
_t=setTimeout(clock,10);
}
_t=setTimeout(clock,10);
var $=function(x){
return document.getElementById(x);
};
var _t;
var clock=function(){
var t=$('clock').innerHTML;
if(t<=0){
clearTimeout(_t);
return;
}
t=parseFloat(t-0.01);
t=t.toFixed(2);
$('clock').innerHTML=t;
_t=setTimeout(clock,10);
}
_t=setTimeout(clock,10);
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
<!DOCTYPE html>
<html lang="en" xmlns="
<head>
<meta charset="utf-8" />
<title></title>
<style type="text/css">
#time {
width: 80px;
height: 48px;
line-height:48px;
text-align:center;
margin: 30px auto;
font-size: 32px;
border:1px solid #3b7936;
}
</style>
</head>
<body>
<div id="time" title="click to start count" onclick="startCount()">
</div>
<script type="text/javascript">
var a = 10;
var handle;
var time = document.getElementById('time');
time.innerHTML = a;
function TimeOut() {
time.innerHTML = a;
if (a > 0) a -= 0.01;
else {
a = 0.00;
clearInterval(handle);
}
a = a.toFixed(2);
}
function startCount() {
a = 10;
if (handle) clearInterval(handle);
handle = setInterval(TimeOut, 10);
}
</script>
</body>
</html>
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询