问答详情
源自:7-3 返回/设置年份方法

为什么把年份设置直接放在documente.write(mydate.setFullYear(1994)); 中结果是乱的

<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>获得年份 </title>
<script type="text/javascript">
var mydate=new Date();
var myyear=mydate.getFullYear();
document.write("年份:"+myyear);


document.write(mydate.setFullYear(1994));
</script>
</head>
<body>
</body>
</html>

输出结果为:年份2017763224290162

提问者:慕田峪6997291 2017-03-09 22:52

个回答

  • 慕田峪6997291
    2017-03-10 18:12:22

    明白了,谢谢

  • 清风yx
    2017-03-10 08:07:48

    var mydate=new Date(); 
    var myyear=mydate.getFullYear();

    mydate.setFullYear(1994);

    document.write("年份:"+myyear+"<br>");

    document.write(mydate);

    that's ok

  • 清风yx
    2017-03-10 08:01:59

    mydate.setFullYear(1994),修改年份,但是要输出mydate,而不是年。