hen*_*ron 0 javascript jquery datetime
我用JavaScript和一些小jQuery编写了这段代码,根据日期和通用时间显示一些不同的消息.今天(格林尼治标准时间周四17:00)我应该只看到一条消息但是我看到了两条消息,这很奇怪,因为第二条消息只应该在星期五显示.
这是我的JavaScript:
$(document).ready(function () {
var todaysDate = new Date();
weekday = todaysDate.getDay();
var universalhour = todaysDate.getUTCHours();
if (weekday >= 0) {
if (weekday <= 4) {
if (universalhour >= 14) {
if (universalhour < 23) {
$('div#announcements').append('<br />Test');
}
}
}
}
if (weekday = 5) {
if (universalhour >= 14) {
if (universalhour < 20) {
$('div#announcements').append('<br />Text');
}
}
}
});
Run Code Online (Sandbox Code Playgroud)
这是一个有效的例子:http://jsfiddle.net/YdEgy/
我究竟做错了什么?
问题是
if (weekday = 5) { <-- you are assigning 5 to weekday
Run Code Online (Sandbox Code Playgroud)
你想要==或===