<!DOCTYPE HTML> <html > <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>系好安全带,准备启航</title> <script type="text/javascript"> //通过javascript的日期对象来得到当前的日期,并输出。 function Day(){ var mydate = new Date(); var weekday = ["星期日","星期一","星期二","星期三","星期四","星期五","星期六"]; var str = mydate.getFullYear()+"年"+(mydate.getMonth()+1)+"月"+mydate.getDate()+"日"+" "+weekday[mydate.getDay()] document.write(str); } document.write(Day()); //问题2 //document.write(Day().toString() + "This is a test str!"); </script> </head> <body> </body> </html>
问题1:这样输出文本的话为什么会有个undefined后缀?
问题2:如果改为document.write(Day().toString());虽然可以消除undefined,但是后面的文本输出就无法显示;例如document.write(Day().toString() + "This is a test str!");结果只是输出当前的时间,没有后面的【"This is a test str!"】,这是为什么?