简单的时区时钟功能陷入错误状态,我不知道为什么
The simple timezone clock function falls into incorrect condition and I have no idea why
我实现了一个简单的时区时钟,它不会根据不同的时区更改时间,经过几次调试后我发现它属于不正确的 "if" 条件。这是代码:
var zone = "ho";
alert("1"+zone);
var ft;
var dt = new Date();
var def = dt.getTimezoneOffset()/60;
var gmt = (dt.getHours() + def);
var ending = ":" + IfZero(dt.getMinutes()) + ":" + IfZero(dt.getSeconds());
alert("2"+zone);
if(zone = "local"){
ft = (IfZero(dt.getHours()) + ":" + IfZero(dt.getMinutes()) + ":" + IfZero(dt.getSeconds()));
alert("firelocal");
}else if(zone = "GMT"){
var _GMT =check24(((gmt) > 24) ? ((gmt) - 24) : (gmt));
ft = (IfZero(_GMT) + ":" + IfZero(dt.getMinutes()) + ":" + IfZero(dt.getSeconds()));
}else if(zone = "eniw"){
var eniw =check24(((gmt + (24-12)) > 24) ? ((gmt + (24-12)) - 24) : (gmt + (24-12)));
ft = (IfZero(eniw) + ending);
}else if (zone = "ho"){
var ho =check24(((gmt + 8) > 24) ? ((gmt + 8) - 24) : (gmt + 8));
ft = (IfZero(ho) + ending);
alert("fireho");
}else{
ft = "undefined";
}
alert("3"+zone);
document.getElementById("worldclock").innerHTML = ft;
setTimeout("worldclock()", 5000);
这是警报的输出:
1ho
2ho
firelocal
3local
我现在真的很困惑,因为我不确定函数是如何落入 if(zone = "local") 条件的,即使我为了调试目的明确初始化了 zone="ho" .
谁能告诉我我的功能有什么问题。对不起,如果问题很愚蠢,我刚开始学习 javascript。
你有:
if (zone = "local")
这使得 zone
取 "local"
的值。更改为:
if (zone === "local")
我实现了一个简单的时区时钟,它不会根据不同的时区更改时间,经过几次调试后我发现它属于不正确的 "if" 条件。这是代码:
var zone = "ho";
alert("1"+zone);
var ft;
var dt = new Date();
var def = dt.getTimezoneOffset()/60;
var gmt = (dt.getHours() + def);
var ending = ":" + IfZero(dt.getMinutes()) + ":" + IfZero(dt.getSeconds());
alert("2"+zone);
if(zone = "local"){
ft = (IfZero(dt.getHours()) + ":" + IfZero(dt.getMinutes()) + ":" + IfZero(dt.getSeconds()));
alert("firelocal");
}else if(zone = "GMT"){
var _GMT =check24(((gmt) > 24) ? ((gmt) - 24) : (gmt));
ft = (IfZero(_GMT) + ":" + IfZero(dt.getMinutes()) + ":" + IfZero(dt.getSeconds()));
}else if(zone = "eniw"){
var eniw =check24(((gmt + (24-12)) > 24) ? ((gmt + (24-12)) - 24) : (gmt + (24-12)));
ft = (IfZero(eniw) + ending);
}else if (zone = "ho"){
var ho =check24(((gmt + 8) > 24) ? ((gmt + 8) - 24) : (gmt + 8));
ft = (IfZero(ho) + ending);
alert("fireho");
}else{
ft = "undefined";
}
alert("3"+zone);
document.getElementById("worldclock").innerHTML = ft;
setTimeout("worldclock()", 5000);
这是警报的输出:
1ho
2ho
firelocal
3local
我现在真的很困惑,因为我不确定函数是如何落入 if(zone = "local") 条件的,即使我为了调试目的明确初始化了 zone="ho" .
谁能告诉我我的功能有什么问题。对不起,如果问题很愚蠢,我刚开始学习 javascript。
你有:
if (zone = "local")
这使得 zone
取 "local"
的值。更改为:
if (zone === "local")