<script type="text/javascript">
var mydate=new Date();
var weekday=["星期一","星期二","星期三","星期四","星期五","星期六","星期日"];
document.write("今天是:" + mydate.getDay());
</script>
请问一下,var weekday=["星期一","星期二","星期三","星期四","星期五","星期六","星期日"];这个有什么作用?因为我试过把他删除了对结果是没有影响的,这里为什么要写他呀?
你输出的结果肯定是数字吧?这里你想要输出星期几的话就要用到weekday这个数组啊,因为getDay()方法返回的是数值,所以你想知道星期几得创建weekday这样的数组。你在最后的结果中没有调用数组,当然不会有效果。应该这样,前面加个weekday。
<script type="text/javascript"> var mydate=new Date(); var weekday=["星期一","星期二","星期三","星期四","星期五","星期六","星期日"]; document.write("今天是:" + weekday[mydate.getDay()]); </script>