我尝试构建一个简单的代码,它返回当周的当天,但它对我来说根本不起作用:\
$(document).ready(function () {
var d = new Date();
var n;
var weekday;
weekday[0] = "Sunday";
weekday[1] = "Monday";
weekday[2] = "Tuesday";
weekday[3] = "Wednesday";
weekday[4] = "Thursday";
weekday[5] = "Friday";
weekday[6] = "Saturday";
n = weekday[d.getDay()];
});
有谁知道为什么它对我不起作用? 感谢。
答案 0 :(得分:3)
您需要初始化工作日数组:
var weekday = new Array(7);
答案 1 :(得分:3)
使用
var weekday = [];
而不是
var weekday;
答案 2 :(得分:0)
将var weekday
更改为var weekday = []
答案 3 :(得分:0)
或者在定义变量时定义所有元素:
var weekday = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'];