js计时器 比如var a=0 setInterval计时器输出出来a每秒加1 20
setInterval计时器输出出来a每秒加1js计时器 急急急! 展开
是这种?
代码:
<html>
<head>
<title>第三题</title>
</head>
<body>
<input type="text" id="time" style="width:300px" >
<script type="text/javascript">
setInterval(fun,1000);
function fun(){
var d = new Date();
var y = d.getFullYear();
var m = d.getMonth()+1;
var dd = d.getDate();
var week = d.getDay();
var h = d.getHours();
var mm = d.getMinutes();
var s = d.getSeconds();
if(y>12){
var t = y+"年"+m+"月"+dd+"日 星期"+week+" "+h+":"+mm+":"+s+" PM"
}else{
var t = y+"年"+m+"月"+dd+"日 星期"+week+" "+h+":"+mm+":"+s+" AM"
}
document.getElementById("time").value=t;
}
</script>
</body>
</html>
2016-12-22
setInterval(a++,1000);