第一種寫法
var str = "" ;
var week = new Date().getDay();
if (week == 0) {
str = "今天是星期日"==; {
str = "今天是星期一";
} else if (week == 2) {
str = "今天是星期三";
} else if (week == 4) {
==str = "今天是星期四; > str = "今天是星期五";
} else if (week == 6) {
str = "今天是星期六"; 🎜>> > alert(str);
第二張寫法
複製代碼
switch (week) {
🎜> str = "日";
str = "一個";
str = "二";
break;
case 3:
break;
case 4 :
break;
case 5 :
str = "五";
str = "六";
>
第三種寫法
複製程式碼
程式碼如下:
Array("日", "一", "二", "三", "四", "五", "六");
var week = new Date().getDay();
var str = "今天是星期" a[week];
alert(str);
第四寫法
var str = "今天是星期" "日一二三四五六".charAt(new Date().getDay()) ;alert(str);