guipeng
2017-03-04 22:02
<!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();
num=time.getDay();
weekend=["星期日","星期一","星期二","星期三","星期四","星期五","星期六"];
attime=time.getFullYear()+"年"+time.getMonth()+"月"+time.getHours()+":"+time.getMinutes()+":"+time.getSeconds() +weekend[num];
document.getElementById("clock").value = attime;
}
var int=setInterval(clock,1000);
</script>
</head>
<body>
<form>
<input type="text" id="clock" size="50" />
</form>
</body>
</html>
为什么显示的月份不对,日期也不对只有年份是对的
月份加一
中文与英文有区别哦
那个月份要加一 具体可以看那个章节
<!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();
num=time.getDay();
weekend=["星期日","星期一","星期二","星期三","星期四","星期五","星期六"];
attime=time.getFullYear()+"年"+(time.getMonth()+1)+"月"+time.getDate()+"日"+time.getHours()+":"+time.getMinutes()+":"+time.getSeconds() +weekend[num];
document.getElementById("clock").value = attime;
}
var a=setInterval(clock,1000);
</script>
</head>
<body>
<form>
<input type="text" id="clock" size="50" />
</form>
</body>
</html>
JavaScript进阶篇
468061 学习 · 21891 问题
相似问题