我想要在數字<10的狀況加一個0
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>定时器</title>
<script type="text/javascript">
var attime;
function clock(){
var time=new Date();
var SecondsAlt;
if (parseInt(time.getSeconds()) <10){
SecondsAlt = "0"+time.getSeconds()
};
else{
SecondsAlt = time.getSeconds()
}
attime=time.getHours()+":"+time.getMinutes()+":"+SecondsAlt;
document.getElementById("clock").value = attime;
}
setInterval(clock,100)
</script>
</head>
<body>
<form>
<input type="text" id="clock" size="50" />
</form>
</body>
</html>請問我這樣寫,哪裡有bug,謝謝
目的:12:50:1 -> 12:50:01