在js中做一个时间效果,使用setInterval方法每秒调用一次显示时间的Function达到动态的效果,但是运行一会浏览器卡死,求解决方法!
function timer()
{
var nowDate = new Date();
//获取年
var year = nowDate.getFullYear();
//月
var month = nowDate.getMonth() + 1;
if (month < 10) {month = "0" + month;};
//日
var dd = nowDate.getDate();
if (dd < 10) {dd = "0" + dd;};
//时
var hh = nowDate.getHours();
if (hh < 10) {hh = "0" + hh;};
//分
var mm = nowDate.getMinutes();
if (mm < 10) {m = "0" + mm;};
//秒
var ss = nowDate.getSeconds();
if (ss < 10) {ss = "0" + ss;};
//上午/下午
var statu = hh > 12?"PM":"AM";
document.getElementById("nowid").innerHTML = year + "年" + month + "月" + dd + "日 " + hh + ":" + mm + ":" + ss + " " + statu;
setInterval("timer()",1000);
}
添加回答
举报
0/150
提交
取消