小编Gre*_*lan的帖子

函数嵌套在if语句中

如果有人能帮助我,我会遇到以下代码的问题我会非常感激.基本上我在调用网址的页面上的几个页面上有几个链接.目前,/freeten/即使在窗口中打开了extraten页面,它也只在代码部分内调用该函数.

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/";
        }

    }
}
Run Code Online (Sandbox Code Playgroud)

javascript location if-statement function match

3
推荐指数
1
解决办法
123
查看次数

标签 统计

function ×1

if-statement ×1

javascript ×1

location ×1

match ×1