gpt4 book ai didi

javascript - 嵌套在 if 语句中的函数

转载 作者:塔克拉玛干 更新时间:2023-11-02 22:35:07 26 4
gpt4 key购买 nike

如果有人可以帮助我,我将在以下代码中遇到问题,我将不胜感激。基本上我在调用 url 的页面上的几个页面上有几个链接。目前它只调用代码的 /freeten/ 部分中的函数,即使扩展页面在窗口中打开也是如此。

if(location.href.match('/extraten/')) {

console.log(window.location.href);

function downloadXM() {
if(location.href.match('/en/')) {
window.location.href = "http://core77.com/";
}

if(location.href.match('/fr/')) {
window.location.href = "http://www.notcot.org/";
}

if(location.href.match('/de/')) {
window.location.href = "http://www.spd.org/";
}

if(location.href.match('/it/')) {
window.location.href = "http://sxsw.com/";
}

}
}

if(location.href.match('/freeten/')) {

function downloadXM() {

if(location.href.match('/en/')) {
window.location.href = "http://www.wired.com/";
}

if(location.href.match('/fr/')) {
window.location.href = "http://www.bbc.co.uk/";
}

if(location.href.match('/de/')) {
window.location.href = "http://edition.cnn.com/";
}

if(location.href.match('/it/')) {
window.location.href = "http://www.sky.com/";
}

}
}

最佳答案

与其以这种方式声明函数,不如尝试这样做:

var myFunc;

if (something) {
myFunc = function () { ... }
} else if (something) {
myFunc = function () { ... }
}

关于javascript - 嵌套在 if 语句中的函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15906420/

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