本文主要是介绍js实现时间走动效果,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
用jQuery获取网页元素赋值即可,已用红色高亮显示(此方法务必初始加载):
function showLeftTime()
{var now=new Date();
var year=now.getFullYear();
var month=now.getMonth()+1;
if(month<10){
month='0'+month;
}
var day=now.getDate();
if(day<10){
day='0'+day;
}
var hours=now.getHours();
if(hours<10){
hours='0'+hours;
}
var minutes=now.getMinutes();
if(minutes<10){
minutes='0'+minutes;
}
var seconds=now.getSeconds();
if(seconds<10){
seconds='0'+seconds;
}
var showTime=year+"年"+month+"月"+day+"日 "+hours+":"+minutes+":"+seconds+"";
$('#nowTime').html(showTime);
//一秒刷新一次显示时间
var timeID=setTimeout(showLeftTime,1000);
}
这篇关于js实现时间走动效果的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!