四夕云遗
2018-07-09 16:26
<html>
<head>
<title>计时器</title>
<script type="text/javascript">
var mydate=new Date();
var myyear=mydate.getFullYear();
var mymonth=mydate.getMonth()+1;
var myday=mydate.getDate();
var myhour=mydate.getHours();
var myminute=mydate.getMinutes();
var mysecond=mydate.getSeconds();
while(1){
document.write(myyear+"年"+mymonth+"月"+myday+"日"+myhour+"时"+myminute+"分"+mysecond+"秒");
}
</script>
</head>
<body>
</body>
</html>
你需要循环的是new Date();
function ChangeTime(){ var mydate=new Date(); var myyear=mydate.getFullYear(); var mymonth=mydate.getMonth()+1; var myday=mydate.getDate(); var myhour=mydate.getHours(); var myminute=mydate.getMinutes(); var mysecond=mydate.getSeconds(); //document.write(myyear+"年"+mymonth+"月"+myday+"日"+myhour+"时"+myminute+"分"+mysecond+"秒"); console.log(myyear+"年"+mymonth+"月"+myday+"日"+myhour+"时"+myminute+"分"+mysecond+"秒"); } setInterval(ChangeTime,1000); F12开发者工具里面看变化
请问你说的是这样吗?
while(1){
var mydate=new Date();
var myyear=mydate.getFullYear();
var mymonth=mydate.getMonth()+1;
var myday=mydate.getDate();
var myhour=mydate.getHours();
var myminute=mydate.getMinutes();
var mysecond=mydate.getSeconds();
document.write(mydate);
document.write(myyear+"年"+mymonth+"月"+myday+"日"+myhour+"时"+myminute+"分"+mysecond+"秒");
}
JavaScript进阶篇
468061 学习 · 21891 问题
相似问题