<html>????
<head>????
<meta?http-equiv="Content-Type"?content="text/html;?charset=utf-8"?/>????
<title>簡(jiǎn)易網(wǎng)頁(yè)時(shí)鐘</title>????
<style>????
body,div{margin:0;padding:0;}????
body{color:#fff;font:16px/1.5?\5fae\8f6f\96c5\9ed1;}????
#clock{width:300px;text-align:center;background:#1a1a1a;margin:10px?auto;padding:20px?0;}????
span{color:#000;width:80px;line-height:2;background:#fbfbfb;border:2px?solid?#b4b4b4;margin:0?10px;padding:0?10px;}????
</style>????
<script>????
window.onload?=?function?()????
{????
var?oClock?=?document.getElementById("clock");
????
var?aSpan?=?oClock.getElementsByTagName("span");????
setInterval(getTimes,?1000);????
getTimes();????
function?getTimes?()????
{????
var?oDate?=?new?Date();????
var?aDate?=?[oDate.getHours(),?oDate.getMinutes(),?oDate.getSeconds()];????
for?(var?i?in?aDate)?aSpan[i].innerHTML?=?format(aDate[i])????
}????
function?format(a)????
{????
return?a.toString().replace(/^(\d)$/,?"0$1")
????
}????
}????
</script>????
</head>????
<body>????
<div?id="clock">????
<span></span>點(diǎn)<span></span>分<span></span>秒????
</div>????
</body>????
</html>上述代碼中,format函數(shù)那部分不太懂,為什么會(huì)有個(gè)a,tostring是將對(duì)象轉(zhuǎn)換為字符串,可是a是哪個(gè)對(duì)象,并沒有定義啊,那么是把誰(shuí)轉(zhuǎn)換為字符串呢?
關(guān)于format函數(shù)
刺槐少女
2018-04-03 10:50:27