为什么直接写出方法就可以正常显示?
<!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.setFullYear(2015); document.write("年份:"+mydate + "<br/>") mydate.setFullYear(49) document.write("年份:"+mydate); </script> </head> <body> </body> </html>
mydate.setFullYear(2015);不是mydate,要想实现效果是
mydate.setFullYear(2015);
var myyear = mydate.getFullYear()