ailing20
2016-07-28 09:10
怎么让计时器按照时:分:秒显示,没有闪烁
var attime;
function clock(){
var time=new Date();
var hour=aa(time.getHours());
var minute=aa(time.getMinutes());
var second=aa(time.getSeconds());
attime=hour+":"+minute+":"+second;
document.getElementById("clock").value = attime;
}
function aa(x){
if(x<10)
{
return "0"+x;
}else{
return x;
}
}
setInterval(clock,100);
window.onload = function(){
var HH = 0;
var mm = 0;
var ss = 0;
var str = '';
var timer = setInterval(function(){
str = "";
if(++ss==60)
{
if(++mm==60)
{
HH++;
mm=0;
}
ss=0;
}
str+=HH<10?"0"+HH:HH;
str+=":";
str+=mm<10?"0"+mm:mm;
str+=":";
str+=ss<10?"0"+ss:ss;
document.getElementById("d").innerHTML = str;
},1000);
};
var i;
function sj()
{
var js=new Date();
document.getElementById("xs").value=js.getHours()+"时"+js.getMinutes()+"分"+js.getSeconds()+"秒";
}setInterval("sj()",1000);
定义了一个input,id为"xs"
JavaScript进阶篇
468194 学习 · 21891 问题
相似问题