求大神帮忙简化下这段代码
<div id = "aa"></p>
<script>
function getTime(){
var aa = document.getElementById("aa");
time = new Date();
year = time.getFullYear();
month = time.getMonth() + 1;
day = time.getDate();
hour = time.getHours();
minutes = time.getMinutes();
seconds = time.getSeconds();
if(minutes<10){
minutes = '0'+minutes;
}
if(seconds<10){
seconds = '0'+seconds;
}
if(month<10){
month = '0'+ month;
}
if(day<10){
day = '0'+ day;
}
aa.innerHTML = year +"-"+ month +"-"+ day + " " +hour+":"+minutes+":"+seconds;
setTimeout(getTime,1000);
}
window.onload = function(){
getTime();
}
</script>
上面有4个判断<10的 想让大神帮忙简化下 另外这段获取时间的代码 是否有兼容问题呢?
<script>
function getTime(){
var aa = document.getElementById("aa");
time = new Date();
year = time.getFullYear();
month = time.getMonth() + 1;
day = time.getDate();
hour = time.getHours();
minutes = time.getMinutes();
seconds = time.getSeconds();
if(minutes<10){
minutes = '0'+minutes;
}
if(seconds<10){
seconds = '0'+seconds;
}
if(month<10){
month = '0'+ month;
}
if(day<10){
day = '0'+ day;
}
aa.innerHTML = year +"-"+ month +"-"+ day + " " +hour+":"+minutes+":"+seconds;
setTimeout(getTime,1000);
}
window.onload = function(){
getTime();
}
</script>
上面有4个判断<10的 想让大神帮忙简化下 另外这段获取时间的代码 是否有兼容问题呢?
...全文


