gpt4 book ai didi

javascript - 使用 if、else if 和 else 时出现意外标记 else

转载 作者:行者123 更新时间:2023-12-03 01:16:21 31 4
gpt4 key购买 nike

我在下面的代码中遇到错误。尝试了 if 和 elseif 的所有组合,但无法使其工作。

错误:未捕获的语法错误:意外的标记其他

if(disableAd == 0 && disableWeather == 0) {
window.setTimeout(function(){
window.location.href = "depart18_ad_P.php";
}, RefreshRate);
} elseif(disableWeather == 0) {
window.setTimeout(function(){
window.location.href = "weather.php";
}, RefreshRate);
} else {
window.setTimeout(function(){
window.location.href = "depart18_P.php";
}, RefreshRate);
}

非常感谢您抽出时间。

最佳答案

正如评论中已经指出的,您的 if-else 中有语法错误。但是,您可以使用三元运算符简化代码。

var _href = (disableAd == 0 && disableWeather == 0) 
? 'depart18_ad_P.php'
: ((disableWeather == 0)
? 'weather.php'
: 'depart18_P.php');
window.setTimeout(function() {
window.location.href = _href;
}, RefreshRate);

关于javascript - 使用 if、else if 和 else 时出现意外标记 else,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51999454/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com