问答详情
源自:7-23 编程练习

请问我这段代码哪里错了呀 ?为何无法显示结果

  var mydate=new Date();
  var year=mydate.getFullYear();
  var month=mydate.getMonth()+1;
  var date=mydate.getDate();
  var day=myweek[mydate.getDay()]
  var myweek=["星期日","星期一","星期二","星期三","星期四","星期五","星期六"]
  document.write(year+"年"+month+"月"+date+"日"+day);

提问者:红枣豆浆 2017-10-30 22:13

个回答

  • qq_舒徐_fEIRUZ
    2017-10-31 09:57:34
    已采纳

    myweek这个数组应该是放在day之前合理些,还有,每句代码之后加上”;”

  • qq_舒徐_fEIRUZ
    2017-10-31 10:00:31

    为什么myweek要放在day之前的原因是因为代码是依次执行的,先执行“var day=myweek[mydate.getDay()];”这句,这时候myweek的初始化还没有做,所以day拿不到myweek的值